From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1aDL-0003Lt-68 for qemu-devel@nongnu.org; Wed, 25 Nov 2015 08:34:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1aDG-000296-6y for qemu-devel@nongnu.org; Wed, 25 Nov 2015 08:34:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43846) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1aDG-00028t-1W for qemu-devel@nongnu.org; Wed, 25 Nov 2015 08:34:22 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 969A86566B for ; Wed, 25 Nov 2015 13:34:21 +0000 (UTC) References: <1448300659-23559-1-git-send-email-pbonzini@redhat.com> <1448300659-23559-2-git-send-email-pbonzini@redhat.com> <87a8q2454l.fsf@blackfin.pond.sub.org> From: Paolo Bonzini Message-ID: <5655B8DA.4060808@redhat.com> Date: Wed, 25 Nov 2015 14:34:18 +0100 MIME-Version: 1.0 In-Reply-To: <87a8q2454l.fsf@blackfin.pond.sub.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/4] qjson: replace QString in JSONLexer with GString List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org On 25/11/2015 13:48, Markus Armbruster wrote: > Where does the 3 come from? My hat. :) I don't know---it was in the old patches, and I just brought it on. Oh, found it. GString adds 1 to the size (for the \0); allocating 4 bytes probably seemed like a good idea at the time. However, it also computes the power of two that is >= size + 1, and g_string_new uses 2 as the default length so it _also_ results in allocating four bytes (ceil_pow2(2+1) == 4). Paolo > As long as g_string_truncate() doesn't reallocate, lexer->token will > grow to hold the largest token seen so far, and stay there. > > Why not MAX_TOKEN_SIZE and be done with it? Oh, it's 64 MiB. Ookay, > I'd call that... generous. >