From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: inline build_string performance Date: Tue, 26 Jun 2012 11:46:34 -0700 Organization: UCLA Computer Science Department Message-ID: <4FEA038A.908@cs.ucla.edu> References: <4FE9CCFF.2060309@cs.ucla.edu> <4FE9E374.8010007@yandex.ru> <4FE9E691.9090906@cs.ucla.edu> <4FE9F26E.6010700@yandex.ru> <4FE9F35E.1060309@cs.ucla.edu> <4FE9F84A.9010700@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1340736406 4704 80.91.229.3 (26 Jun 2012 18:46:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 26 Jun 2012 18:46:46 +0000 (UTC) Cc: Emacs Development To: Dmitry Antipov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 26 20:46:45 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sjamj-0003Fm-75 for ged-emacs-devel@m.gmane.org; Tue, 26 Jun 2012 20:46:45 +0200 Original-Received: from localhost ([::1]:33881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjamj-0004Pg-1A for ged-emacs-devel@m.gmane.org; Tue, 26 Jun 2012 14:46:45 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjamg-0004P9-8z for Emacs-devel@gnu.org; Tue, 26 Jun 2012 14:46:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sjame-0005hZ-B6 for Emacs-devel@gnu.org; Tue, 26 Jun 2012 14:46:41 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:58351) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjame-0005h7-2s for Emacs-devel@gnu.org; Tue, 26 Jun 2012 14:46:40 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 0909FA60022; Tue, 26 Jun 2012 11:46:36 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sskkaFanwkfV; Tue, 26 Jun 2012 11:46:35 -0700 (PDT) Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 3D969A60019; Tue, 26 Jun 2012 11:46:35 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 In-Reply-To: <4FE9F84A.9010700@yandex.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151196 Archived-At: On 06/26/2012 10:58 AM, Dmitry Antipov wrote: > build_string is a macro which expands to > build_literal (S, strlen (S)) if S is a compile-time constant, > and to make_string (S, strlen (S)) otherwise. Yes, but in the latter case there is code bloat but no compensating performance benefit. How about the following instead? === modified file 'src/alloc.c' --- src/alloc.c 2012-06-26 14:41:01 +0000 +++ src/alloc.c 2012-06-26 18:43:25 +0000 @@ -2496,6 +2496,20 @@ } +/* Make a string from the data at STR, treating it as multibyte if the + data warrants. */ + +Lisp_Object +build_string_1 (const char *str) +{ + return make_string (str, strlen (str)); +} + +/* Make the build_string macro visible to GDB. */ +extern Lisp_Object (build_string) (const char *) EXTERNALLY_VISIBLE; +Lisp_Object (build_string) (const char *s) { return build_string (s); } + + /* Return an unibyte Lisp_String set up to hold LENGTH characters occupying LENGTH bytes. */ @@ -2533,6 +2547,27 @@ return string; } +#ifdef __GNUC__ +/* Fast version used when both STR and NBYTES are compile-time + constants, and all characters from STR are ASCII. */ + +Lisp_Object +build_literal (const char *str, ptrdiff_t nbytes) +{ + Lisp_Object string; + struct Lisp_String *s; + + eassert (nbytes > 0); + + s = allocate_string (); + allocate_string_data (s, nbytes, nbytes); + memcpy (s->data, str, nbytes); + string_chars_consed += nbytes; + + XSETSTRING (string, s); + return string; +} +#endif /*********************************************************************** === modified file 'src/lisp.h' --- src/lisp.h 2012-06-26 05:00:30 +0000 +++ src/lisp.h 2012-06-26 18:36:28 +0000 @@ -2715,12 +2715,19 @@ /* Make a string from the data at STR, treating it as multibyte if the data warrants. */ - -static inline Lisp_Object -build_string (const char *str) -{ - return make_string (str, strlen (str)); -} +extern Lisp_Object build_string_1 (const char *); +#ifdef __GNUC__ +extern Lisp_Object build_literal (const char *, ptrdiff_t); +# define build_string(str) \ + ({ Lisp_Object __val; \ + if (__builtin_constant_p (str) && strlen (str) > 0) \ + __val = build_literal (str, strlen (str)); \ + else \ + __val = build_string_1 (str); \ + __val; }) +#else +# define build_string(str) build_string_1 (str) +#endif extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object); EXFUN (Fgarbage_collect, 0);