--QKdGvSO+nmPlgiQ/
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jul 06, 2011 at 07:01:37AM +0900, Luis Lavena wrote:
> On Tue, Jul 5, 2011 at 6:56 PM, Aaron Patterson
> <aaron / tenderlovemaking.com> wrote:
> >
> > We can also help rbconfig go on a diet. =A0I know it's not enough, but
> > this eliminated ~400 object allocations on my machine. =A0(what is the
> > MAKEFILE_CONFIG for anyway?)
>=20
> Is used by mkmf, which raises another round of questions: why is not
> using RbConfig::CONFIG directly?

I assume it's so that if someone mutates the hash, it doesn't impact the
RbConfig::CONFIG hash.  Though, if that's the case, why doesn't mkmf.rb
just dup the hash rather than relying on rbconfig.

Maybe this patch is more appropriate:

diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 9b0b8c7..efaa603 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -6,7 +6,7 @@ require 'rbconfig'
 require 'fileutils'
 require 'shellwords'
=20
-CONFIG =3D RbConfig::MAKEFILE_CONFIG
+CONFIG =3D RbConfig.makefile_config
 ORIG_LIBPATH =3D ENV['LIB']
=20
 C_EXT =3D %w[c m]
diff --git a/template/fake.rb.in b/template/fake.rb.in
index 7bfa0ae..b487a79 100755
--- a/template/fake.rb.in
+++ b/template/fake.rb.in
@@ -24,7 +24,7 @@ end
=20
 $:.unshift(File.expand_path("..", __FILE__))
 posthook =3D proc do
-  mkconfig =3D RbConfig::MAKEFILE_CONFIG
+  mkconfig =3D RbConfig.makefile_config
   extout =3D File.expand_path(mkconfig["EXTOUT"], mkconfig["builddir"])
   $arch_hdrdir =3D "#{extout}/include/$(arch)"
   $ruby =3D baseruby
@@ -33,7 +33,7 @@ end
 prehook =3D proc do |extmk|
   unless extmk
     config =3D RbConfig::CONFIG
-    mkconfig =3D RbConfig::MAKEFILE_CONFIG
+    mkconfig =3D RbConfig.makefile_config
     builddir =3D File.expand_path(File.dirname(__FILE__))
     mkconfig["top_srcdir"] =3D $top_srcdir =3D File.expand_path("@top_srcd=
ir@", builddir)
     mkconfig["rubyhdrdir"] =3D "$(top_srcdir)/include"
diff --git a/tool/compile_prelude.rb b/tool/compile_prelude.rb
index 6ad9fce..0674754 100755
--- a/tool/compile_prelude.rb
+++ b/tool/compile_prelude.rb
@@ -49,9 +49,9 @@ class Prelude
         key =3D $1
         unless @mkconf
           require './rbconfig'
-          @mkconf =3D RbConfig::MAKEFILE_CONFIG.merge('prefix'=3D>'#{TMP_R=
UBY_PREFIX}')
+          @mkconf =3D RbConfig.makefile_config.merge('prefix'=3D>'#{TMP_RU=
BY_PREFIX}')
         end
-        if RbConfig::MAKEFILE_CONFIG.has_key? key
+        @mkconf.has_key? key
           val =3D RbConfig.expand("$(#{key})", @mkconf)
           @need_ruby_prefix ||=3D /\A\#\{TMP_RUBY_PREFIX\}/ =3D~ val
           c_esc(val)
diff --git a/tool/mkconfig.rb b/tool/mkconfig.rb
index a2221f0..e924696 100755
--- a/tool/mkconfig.rb
+++ b/tool/mkconfig.rb
@@ -202,8 +202,6 @@ print <<EOS
   CONFIG["vendorlibdir"] =3D "$(vendordir)/$(ruby_version)"
   CONFIG["vendorarchdir"] =3D "$(vendorlibdir)/$(sitearch)"
   CONFIG["topdir"] =3D File.dirname(__FILE__)
-  MAKEFILE_CONFIG =3D {}
-  CONFIG.each{|k,v| MAKEFILE_CONFIG[k] =3D v.dup}
   def RbConfig::expand(val, config =3D CONFIG)
     newval =3D val.gsub(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) {
       var =3D $&
@@ -233,6 +231,17 @@ print <<EOS
       RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
     )
   end
+
+  def self.makefile_config
+    hash =3D CONFIG.dup
+    hash.each { |k,v| hash[k] =3D v.dup }
+  end
+
+  def self.const_missing const
+    return super unless :MAKEFILE_CONFIG =3D=3D const
+    const_set :MAKEFILE_CONFIG, makefile_config
+    MAKEFILE_CONFIG
+  end
 end
 autoload :Config, "rbconfig/obsolete.rb" # compatibility for ruby-1.8.4 an=
d older.
 CROSS_COMPILING =3D nil unless defined? CROSS_COMPILING
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 0b1361a..34be069 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -968,7 +968,7 @@ $(ruby_pc): $(RBCONFIG)
 	@$(MINIRUBY) -r./rbconfig -p \
 	-e 'STDOUT.binmode' \
 	-e '$$_.gsub!(/@([a-z_]\w*)@/i) {' \
-	-e '(RbConfig::MAKEFILE_CONFIG[$$1] or "").gsub(/\$$\((.+?)\)/, %Q[$${\\1=
}])' \
+	-e '(RbConfig::CONFIG[$$1] or "").gsub(/\$$\((.+?)\)/, %Q[$${\\1}])' \
 	-e '}' \
 	$(srcdir)/template/ruby.pc.in > $@
=20
diff --git a/win32/resource.rb b/win32/resource.rb
index 786edb0..34a1df2 100755
--- a/win32/resource.rb
+++ b/win32/resource.rb
@@ -2,7 +2,7 @@
=20
 require './rbconfig'
=20
-CONFIG =3D RbConfig::MAKEFILE_CONFIG
+CONFIG =3D RbConfig.makefile_config
=20
 version =3D RUBY_VERSION.split(/\./)
 patch =3D CONFIG['PATCHLEVEL']

--=20
Aaron Patterson
http://tenderlovemaking.com/

--QKdGvSO+nmPlgiQ/
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)

iQEcBAEBAgAGBQJOE43YAAoJEJUxcLy0/6/GSGsH/2YIpgpAew2g2hNCiSWquv2h
xpFmx6hebVpLxpO0qyo4rkYRt6NYqakN8MjNr0SuefdGiZfBXuh3mye6NthdNd1i
buHw5WLxcmjY750ghdSrFb29UlDnOONBcJIKJeVIL2JwaXsxNa1pQjRnltKsqhPu
b96DRlTfgTwZGI/CeBglZj3z6Sr9B5cyjtrDhu584ORXu7NgvYMdacQhTSG71/Am
NithvshKkV9X9ME6iKG2hFbOqytPH3e1HjxT4nyUADQAZoxotAGVTwrjlbrCQzPk
zhX9Y8BlddnVaqC6eM5p6alPVE4J6x6Dxss3uulhvz+WmKz039KFrhmN4DpXE6Y=
=cSEL
-----END PGP SIGNATURE-----

--QKdGvSO+nmPlgiQ/--