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.bugs Subject: bug#22763: 25.1.50; Feature Request -- A faster method to obtain line number at position. Date: Sun, 07 Feb 2021 20:09:59 +0200 Message-ID: <83eehrn408.fsf@gnu.org> References: <83y4aclofm.fsf@gnu.org> <878s7z532u.fsf@gnus.org> <87y2fz3lpe.fsf@gnus.org> <87h7mn22ls.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2625"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 22763@debbugs.gnu.org, esq@lawlist.com, monnier@iro.umontreal.ca To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 07 19:10:22 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1l8oVp-0000Yp-HT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 19:10:21 +0100 Original-Received: from localhost ([::1]:52856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8oVo-0000nE-92 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Feb 2021 13:10:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8oVW-0000l1-35 for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 13:10:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37157) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8oVV-0006fl-Ro for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 13:10:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l8oVV-0001Io-Lw for bug-gnu-emacs@gnu.org; Sun, 07 Feb 2021 13:10:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Feb 2021 18:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22763 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 22763-submit@debbugs.gnu.org id=B22763.16127213984993 (code B ref 22763); Sun, 07 Feb 2021 18:10:01 +0000 Original-Received: (at 22763) by debbugs.gnu.org; 7 Feb 2021 18:09:58 +0000 Original-Received: from localhost ([127.0.0.1]:48703 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8oVR-0001IT-UV for submit@debbugs.gnu.org; Sun, 07 Feb 2021 13:09:58 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:34194) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8oVP-0001IF-Ii for 22763@debbugs.gnu.org; Sun, 07 Feb 2021 13:09:57 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:34107) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8oVJ-0006an-P1; Sun, 07 Feb 2021 13:09:49 -0500 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2620 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l8oVI-0002Rf-SR; Sun, 07 Feb 2021 13:09:49 -0500 In-Reply-To: <87h7mn22ls.fsf@gnus.org> (message from Lars Ingebrigtsen on Sun, 07 Feb 2021 18:45:51 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199530 Archived-At: > From: Lars Ingebrigtsen > Cc: Eli Zaretskii , 22763@debbugs.gnu.org, Keith David > Bershatsky > Date: Sun, 07 Feb 2021 18:45:51 +0100 > > Stefan Monnier writes: > > > Why is it faster? > > > > Is it still always Θ(N) just with a smaller constant (if so, what makes > > the constant smaller), or does it benefit from some kind of caching > > (which I fail to see in the code) such that it's O(N) sometimes but much > > faster other times (and if so, what are the cases that are sped up)? > > There's no caching. I guess find_newline is just slow compared to > display_count_lines? find_newline does the same as display_count_lines: it calls memchr. But it also maintains a newline cache. If you disable that cache (by turning of cache-long-scans), you might see a different speedup. Also, calling forward-line would loop in Lisp, not in C.