From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: woman.el broken? Date: Sat, 06 Mar 2021 10:07:16 +0200 Message-ID: <83wnukwvrf.fsf@gnu.org> References: <20210301193951.7EB04C217D7@raman-glaptop.localdomain> <878s763bah.fsf@gnus.org> <83r1ky7icm.fsf@gnu.org> <87zgzm1vvf.fsf@gnus.org> <83mtvm7hkt.fsf@gnu.org> <83lfb469e7.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37109"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, emacs-devel@gnu.org To: Stefan Kangas Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Mar 06 09:08:17 2021 Return-path: Envelope-to: ged-emacs-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 1lIRyz-0009Z7-23 for ged-emacs-devel@m.gmane-mx.org; Sat, 06 Mar 2021 09:08:17 +0100 Original-Received: from localhost ([::1]:32954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIRyy-0004CD-3h for ged-emacs-devel@m.gmane-mx.org; Sat, 06 Mar 2021 03:08:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIRyH-0003lI-4E for emacs-devel@gnu.org; Sat, 06 Mar 2021 03:07:33 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34842) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIRyG-0004go-An; Sat, 06 Mar 2021 03:07:32 -0500 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4127 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lIRyE-00035n-8b; Sat, 06 Mar 2021 03:07:32 -0500 In-Reply-To: (message from Stefan Kangas on Fri, 5 Mar 2021 19:43:24 -0800) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:266058 Archived-At: > From: Stefan Kangas > Date: Fri, 5 Mar 2021 19:43:24 -0800 > Cc: larsi@gnus.org, emacs-devel@gnu.org > > >> If this is performant enough, I don't at the moment see any reason to > >> have it in C. Of course, the few places that call Flookup_key from C > >> will need to be analyzed whether they need to call the internal > >> function or the Lisp wrapper, and modified accordingly. > > > > OK. I will write up the patch and do some benchmarks. > > Turns out this was actually easier and faster to just do in C, as there > were less places that needed changing. See the attached diff. Thanks. > The thing that is missing now is converting Foo\ Bar to foo-bar, but > what is the best method for doing that from C? Should I just call out > to `string-replace' or is there a better way? Something like this should do: . copy the original string data to a local buffer (use USE_SAFE_ALLOCA and SAFE_ALLOCA to allocate a suitable buffer) . replace each space with a '-' in a simple loop that examines each character in the above buffer . use build_string to create a new string from the replaced contents > + Lisp_Object new_key = Fmake_vector (make_fixnum (ASIZE (key)), Qnil); I think it's better to use make_vector here. A general comment: many Emacs primitives are just thin wrappers around C functions; those wrappers typically take care of checking the type of the arguments, converting Lisp data types to C data types, etc. In this case, you will see that Fmake_vector calls make_vector, which is its workhorse. When calling those primitives from C, it is generally better to call the C workhorse instead of the primitive, because that avoids wasting cycles on checking data types that are already known in advance (by C rules) to be correct, and consing Lisp data from the underlying C data (like the call to make_fixnum in this case, but it's even more start when you need to make a Lisp string from a C string). The convenience of such calls from C is actually one reason why we generally prefer to implement primitives in this 2-layer fashion.