From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rob Browning Newsgroups: gmane.lisp.guile.devel Subject: [PATCH 1/1] scm_set_source_properties_x: optimize if only name, line, and/or col Date: Sun, 17 Jan 2021 16:24:58 -0600 Message-ID: <20210117222458.902736-1-rlb@defaultvalue.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38166"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sun Jan 17 23:25:23 2021 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1GU7-0009pI-5b for guile-devel@m.gmane-mx.org; Sun, 17 Jan 2021 23:25:23 +0100 Original-Received: from localhost ([::1]:48410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1GU6-0005q0-0L for guile-devel@m.gmane-mx.org; Sun, 17 Jan 2021 17:25:22 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1GTp-0005or-CH for guile-devel@gnu.org; Sun, 17 Jan 2021 17:25:05 -0500 Original-Received: from defaultvalue.org ([45.33.119.55]:47986) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1GTl-0007zE-FJ for guile-devel@gnu.org; Sun, 17 Jan 2021 17:25:05 -0500 Original-Received: from trouble.defaultvalue.org (localhost [127.0.0.1]) (Authenticated sender: rlb@defaultvalue.org) by defaultvalue.org (Postfix) with ESMTPSA id DB584204E1 for ; Sun, 17 Jan 2021 16:24:58 -0600 (CST) Original-Received: by trouble.defaultvalue.org (Postfix, from userid 1000) id 7B63514E63A; Sun, 17 Jan 2021 16:24:58 -0600 (CST) X-Mailer: git-send-email 2.29.2 Received-SPF: pass client-ip=45.33.119.55; envelope-from=rlb@defaultvalue.org; helo=defaultvalue.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20639 Archived-At: * libguile/srcprop.c (scm_set_source_properties_x): When only a subset of file, line, and column fields are specified, store the data as a srcprops object (tc16_srcprops) rather than an alist. --- Proposed for at least 3.x. If we want some additional tests, then one option might be a public or private predicate to test for a srcprops object (at least for scheme level testing). libguile/srcprop.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libguile/srcprop.c b/libguile/srcprop.c index 0ebbfc301..fea68e031 100644 --- a/libguile/srcprop.c +++ b/libguile/srcprop.c @@ -168,8 +168,6 @@ SCM_DEFINE (scm_source_properties, "source-properties", 1, 0, 0, #define SCM_VALIDATE_NIM(pos, scm) \ SCM_MAKE_VALIDATE_MSG (pos, scm, NIMP, "non-immediate") -/* Perhaps this procedure should look through an alist - and try to make a srcprops-object...? */ SCM_DEFINE (scm_set_source_properties_x, "set-source-properties!", 2, 0, 0, (SCM obj, SCM alist), "Install the association list @var{alist} as the source property\n" @@ -177,9 +175,17 @@ SCM_DEFINE (scm_set_source_properties_x, "set-source-properties!", 2, 0, 0, #define FUNC_NAME s_scm_set_source_properties_x { SCM_VALIDATE_NIM (1, obj); - - scm_weak_table_putq_x (scm_source_whash, obj, alist); - + SCM fname = scm_assq_ref (alist, scm_sym_filename); + SCM col = scm_assq_ref (alist, scm_sym_column); + SCM line = scm_assq_ref (alist, scm_sym_line); + const int n = ((fname == SCM_BOOL_F) ? 0 : 1) + + ((col == SCM_BOOL_F) ? 0 : 1) + + ((line == SCM_BOOL_F) ? 0 : 1); + + if (scm_ilength (alist) == n) + scm_i_set_source_properties_x (obj, line, col, fname); + else + scm_weak_table_putq_x (scm_source_whash, obj, alist); return alist; } #undef FUNC_NAME -- 2.29.2