From: Thomas Enebo Date: 2008-12-21T01:33:17+09:00 Subject: [ruby-core:20722] Re: [Feature #905] Add String.new(fixnum) to preallocate large buffer Roger Pack wrote: >> Hard to do, since it has to be a hash on the callee side. Constructing the >> hash could perhaps be delayed, in case the callee was a C function, but it >> still has to be something. In comparison, new(1000) is almost free. >> > > I suppose a clever implementation could optimize that out. > -=R > > HEH. So using this logic we have never had a clever implementation of Ruby. Should I laugh or cry? :) Actually, since the syntax of a hash on the end of a method it is at least possible we could modify the grammar to do something special on the front-end (call-side). Then call a special signature on the backend for this hash-called method signature. For regular Ruby-defined methods with hash on the end we construct the hash and pass it as an ordinary argument. For our internally implemented methods (Java) we could pass as a special signature. The C impl maybe could do something similiar. Just trying to be clever. I think this would be almost impossible on a Ruby implemented method. It would require dynamic profiling at best. -Tom