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 C7DD319C037F for ; Thu, 3 Dec 2015 06:05:14 +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 96A2FB5D839 for ; Thu, 3 Dec 2015 06:36:40 +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 C41F518CC7B1 for ; Thu, 3 Dec 2015 06:36:40 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 816C112060A; Thu, 3 Dec 2015 06:36:38 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by neon.ruby-lang.org (Postfix) with ESMTP id A165812045B for ; Thu, 3 Dec 2015 06:36:32 +0900 (JST) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id 9D8272044C; Wed, 2 Dec 2015 21:36:31 +0000 (UTC) Date: Wed, 2 Dec 2015 21:36:31 +0000 From: Eric Wong To: Ruby developers Message-ID: <20151202213631.GA27439@dcvr.yhbt.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ML-Name: ruby-core X-Mail-Count: 71804 Subject: [ruby-core:71804] Re: [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" colin@invoca.com wrote: > Isn't it sufficient to initialize the string buffer with String.new? Yes, but I prefer to avoid String.new because the constant lookup requires an inline cache lookup + storage entry in the iseq. Here's their respective disassembly code: ''.freeze.dup == disasm: #@>================================ 0000 trace 1 ( 1) 0002 opt_str_freeze "" 0004 opt_send_without_block , 0007 leave String.new == disasm: #@>================================ 0000 trace 1 ( 1) 0002 getinlinecache 9, 0005 getconstant :String 0007 setinlinecache 0009 opt_send_without_block , 0012 leave But maybe String.new is slightly faster; but I normally prefer smaller code unless something is called in a tight loop.