From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 9E49C19C05A5 for ; Thu, 3 Dec 2015 13:48:52 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 9FB0FB5D884 for ; Thu, 3 Dec 2015 14:20:18 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 06DB018CC7CC for ; Thu, 3 Dec 2015 14:20:18 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 7B2F5120485; Thu, 3 Dec 2015 14:20:17 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id A22B5120470 for ; Thu, 3 Dec 2015 14:20:13 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=lIXWCcRjwW1GzZC0J5ASl9o2ucc=; b=SWvdmyE6vqGxT4dkiO unNgPIZG+RHx3J+yzBOfT8YWFgQoU2JaUVFMvM1z9bAl1khLxdkKw70jx8hdjA4u HWxboHEX25c+bTDtwOWAIG6RjtvdZzraiqFsPKZBuwI8yfYHLrqf0aZePnaour/h b0UBTpYaAudPaETfVL8x7N/rM= Received: by filter0569p1mdw1.sendgrid.net with SMTP id filter0569p1mdw1.1442.565FD10A24 2015-12-03 05:20:10.42644424 +0000 UTC Received: from herokuapp.com (ec2-54-158-85-149.compute-1.amazonaws.com [54.158.85.149]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id m9TIrhZlTVKG6xGxtpPjZg Thu, 03 Dec 2015 05:20:10.478 +0000 (UTC) Date: Thu, 03 Dec 2015 05:20:10 +0000 From: colin@invoca.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46500 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11759 X-Redmine-Issue-Author: mperham X-Redmine-Sender: colindkelley X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7/oQTLy3bWzN/gcjJe8uukUk9B2ssHWwLf/6 ckx/u28olHJDGatd+5tcQpB2NRroH3c9Rf/z5GREYNpUZZKqplt6FvaWOZfva7QD8/JB3JS0Nzyag+ cA/ZizhIU2Ir4vxD0a77CM5BxfSyymppopaU X-ML-Name: ruby-core X-Mail-Count: 71812 Subject: [ruby-core:71812] [Ruby trunk - Bug #11759] URI breaks with frozen strings X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/