Issue #11759 has been updated by Colin Kelley.


> Yes, but I prefer to avoid String.new because the constant lookup
> requires an inline cache lookup + storage entry in the iseq.

Compared to the surrounding code in the full method, would the extra constant lookup make a measurable difference in code size?

> But maybe String.new is slightly faster; but I normally
> prefer smaller code unless something is called in a tight loop.

If it's the same speed or faster, I would vote for `String.new` because to me it makes the intention the most clear. This seems ugly:

~~~
''.freeze.dup
~~~

because the `.freeze` is temporary for Ruby 2.1 and 2.2, right?  When would this copy of generic.rb ever be run with Ruby versions earlier than 2.3?  Assuming it will just be used for Ruby 2.3 and later, the magic comment included in the patch will implicitly freeze the string literal.  Hence this would also be sufficient (and in my opinion, nearly as clear in intention as `String.new`):

~~~
''.dup
~~~

----------------------------------------
Bug #11759: URI breaks with frozen strings
https://bugs.ruby-lang.org/issues/11759#change-55216

* Author: Mike Perham
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.0-preview1
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
It appears URI uses String mutation and breaks frozen string mode.

~~~
$ RUBYOPT="--enable-frozen-string-literal" bundle exec rake
/Users/mike/.rubies/ruby-2.3.0-preview1/lib/ruby/2.3.0/uri/generic.rb:1344:in `to_s': can't modify frozen String (RuntimeError)
/Users/mike/.gem/ruby/2.3.0/gems/bundler-1.10.6/lib/bundler/source/rubygems.rb:257:in `normalize_uri'
/Users/mike/.gem/ruby/2.3.0/gems/bundler-1.10.6/lib/bundler/source/rubygems.rb:198:in `add_remote'
/Users/mike/.gem/ruby/2.3.0/gems/bundler-1.10.6/lib/bundler/source/rubygems.rb:25:in `block in initialize'
/Users/mike/.gem/ruby/2.3.0/gems/bundler-1.10.6/lib/bundler/source/rubygems.rb:25:in `reverse_each'
/Users/mike/.gem/ruby/2.3.0/gems/bundler-1.10.6/lib/bundler/source/rubygems.rb:25:in `initialize'
~~~

---Files--------------------------------
0001-Do-not-mutate-strings-in-URI-to_s.patch (1.76 KB)
11759.patch (610 Bytes)


-- 
https://bugs.ruby-lang.org/