"Yukihiro Matsumoto" <matz / ruby-lang.org> schrieb im Newsbeitrag
news:1057156227.243350.7287.nullmailer / picachu.netlab.jp...
> Hi,
>
> In message "Re: Memory behavior of String#dup"
>     on 03/07/02, Yukihiro Matsumoto <matz / ruby-lang.org> writes:
>
> |Putting joke aside, frozen key string is very useful for finding
> |bugs.  So I think optimization should be done differently.

You lost me here.  Maybe I wasn't clear enough and we have a
misunderstanding.  I meant - quite informally:

class Hash
def []=(key, val)
  if key.kind_of? String && !key.frozen?
    key = key.dup
    key.freeze
  end

  # now insert key and value
end
end

> Your suggestion inspired me a new dup-freeze optimization.  It'll be
> available soon on the CVS.  Thank you.

You're welcome!  Do you mean a specialized dup method that returns self if
frozen like

class Object
  def dupFreeze
    frozen? ? self : dup
  end
end

Kind regards

    robert