all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
       [not found] ` <20230326104755.356B1C1391D@vcs2.savannah.gnu.org>
@ 2023-03-26 23:05   ` Dmitry Gutov
  2023-03-26 23:35     ` Emanuel Berg
  2023-03-27 12:47     ` Mattias Engdegård
  2023-03-29 15:23   ` Robert Pluim
  1 sibling, 2 replies; 7+ messages in thread
From: Dmitry Gutov @ 2023-03-26 23:05 UTC (permalink / raw)
  To: emacs-devel, Mattias Engdegård

Hi Mathias,

On 26/03/2023 13:47, Mattias Engdegård wrote:
> diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
> index d077c43ba52..d1034d467ab 100644
> --- a/lisp/progmodes/ruby-ts-mode.el
> +++ b/lisp/progmodes/ruby-ts-mode.el
> @@ -469,7 +469,7 @@ non-nil."
>     (let* (first-call )
>       (while (and parent
>                   (setq first-call (treesit-node-parent parent))
> -                (string-match-p "call" (treesit-node-type first-call)))
> +                (string-search "call" (treesit-node-type first-call)))
>         (setq parent first-call))
>       (treesit-node-start (treesit-search-subtree parent "\\." nil t))))

Thanks for this, it uncovered an existing bug in the code.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
  2023-03-26 23:05   ` master 0724c6dbdae: Use string-search instead of string-match[-p] when possible Dmitry Gutov
@ 2023-03-26 23:35     ` Emanuel Berg
  2023-03-27  4:58       ` Yuan Fu
  2023-03-27 12:47     ` Mattias Engdegård
  1 sibling, 1 reply; 7+ messages in thread
From: Emanuel Berg @ 2023-03-26 23:35 UTC (permalink / raw)
  To: emacs-devel

Okay, I've never heard of this, because the byte-compiler
don't complain and it isn't in the docstrings either what
I can see.

I have 14 string-match[-p], so what is the rule when they
should be replaced by `string-search' and when not do that,
and why?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
  2023-03-26 23:35     ` Emanuel Berg
@ 2023-03-27  4:58       ` Yuan Fu
  0 siblings, 0 replies; 7+ messages in thread
From: Yuan Fu @ 2023-03-27  4:58 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: emacs-devel



> On Mar 26, 2023, at 4:35 PM, Emanuel Berg <incal@dataswamp.org> wrote:
> 
> Okay, I've never heard of this, because the byte-compiler
> don't complain and it isn't in the docstrings either what
> I can see.
> 
> I have 14 string-match[-p], so what is the rule when they
> should be replaced by `string-search' and when not do that,
> and why?

When the search string shouldn’t be interpreted as regexp, I presume?

Yuan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
  2023-03-26 23:05   ` master 0724c6dbdae: Use string-search instead of string-match[-p] when possible Dmitry Gutov
  2023-03-26 23:35     ` Emanuel Berg
@ 2023-03-27 12:47     ` Mattias Engdegård
  1 sibling, 0 replies; 7+ messages in thread
From: Mattias Engdegård @ 2023-03-27 12:47 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

27 mars 2023 kl. 01.05 skrev Dmitry Gutov <dgutov@yandex.ru>:

> Thanks for this, it uncovered an existing bug in the code.

Happy to hear that!




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
       [not found] ` <20230326104755.356B1C1391D@vcs2.savannah.gnu.org>
  2023-03-26 23:05   ` master 0724c6dbdae: Use string-search instead of string-match[-p] when possible Dmitry Gutov
@ 2023-03-29 15:23   ` Robert Pluim
  2023-03-29 15:34     ` Mattias Engdegård
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Pluim @ 2023-03-29 15:23 UTC (permalink / raw)
  To: emacs-devel; +Cc: Mattias Engdegård

>>>>> On Sun, 26 Mar 2023 06:47:54 -0400 (EDT), Mattias Engdegård <mattiase@acm.org> said:

    Mattias> branch: master
    Mattias> commit 0724c6dbdaef2c549409836ba4f7999e05aa31fe
    Mattias> Author: Mattias Engdegård <mattiase@acm.org>
    Mattias> Commit: Mattias Engdegård <mattiase@acm.org>

    Mattias>     Use string-search instead of string-match[-p] when possible
    
    Mattias>     * lisp/progmodes/c-ts-mode.el
    Mattias>     (c-ts-mode--standalone-parent-skip-preproc):
    Mattias>     * lisp/progmodes/ruby-ts-mode.el (ruby-ts--align-chain):
    Mattias>     * lisp/treesit.el (treesit-max-buffer-size)
    Mattias>     (treesit--check-manual-coverage):
    Mattias>     Use the much faster string-search when just searching for a substring.
    Mattias> ---
    Mattias>  lisp/progmodes/c-ts-mode.el    | 2 +-
    Mattias>  lisp/progmodes/ruby-ts-mode.el | 2 +-
    Mattias>  lisp/treesit.el                | 4 ++--
    Mattias>  3 files changed, 4 insertions(+), 4 deletions(-)

Hmm, we could do this using a compiler macro, no? Something like

(put 'string-match-p 'compiler-macro
     #'byte-optimize-string-match-p)

(defun byte-optimize-string-match-p (form r string &optional start)
  (if (and (stringp r)
           (string-equal r (regexp-quote r)))
      `(string-search ,r ,string ,start)
    form))

(I donʼt think we can do it unconditionally for `string-match', since
`string-search' doesnʼt set the match data.)

Robert
-- 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
  2023-03-29 15:23   ` Robert Pluim
@ 2023-03-29 15:34     ` Mattias Engdegård
  2023-03-29 15:54       ` Robert Pluim
  0 siblings, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2023-03-29 15:34 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

29 mars 2023 kl. 17.23 skrev Robert Pluim <rpluim@gmail.com>:

> Hmm, we could do this using a compiler macro, no? Something like
> 
> (put 'string-match-p 'compiler-macro
>     #'byte-optimize-string-match-p)

No, that would be incorrect: string-match-p obeys case-fold-search, string-search doesn't.

Replacing string-match[-p] with string-search in the source also makes the code clearer.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: master 0724c6dbdae: Use string-search instead of string-match[-p] when possible
  2023-03-29 15:34     ` Mattias Engdegård
@ 2023-03-29 15:54       ` Robert Pluim
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Pluim @ 2023-03-29 15:54 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: emacs-devel

>>>>> On Wed, 29 Mar 2023 17:34:36 +0200, Mattias Engdegård <mattiase@acm.org> said:

    Mattias> 29 mars 2023 kl. 17.23 skrev Robert Pluim <rpluim@gmail.com>:
    >> Hmm, we could do this using a compiler macro, no? Something like
    >> 
    >> (put 'string-match-p 'compiler-macro
    >> #'byte-optimize-string-match-p)

    Mattias> No, that would be incorrect: string-match-p obeys case-fold-search, string-search doesn't.

Right, Iʼd forgotten about that. And a warning would be a bit
intrusive, I think.

    Mattias> Replacing string-match[-p] with string-search in the source also makes the code clearer.

Thatʼs definitely true.

Robert
-- 



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-29 15:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <167982767456.13549.3313290435008922358@vcs2.savannah.gnu.org>
     [not found] ` <20230326104755.356B1C1391D@vcs2.savannah.gnu.org>
2023-03-26 23:05   ` master 0724c6dbdae: Use string-search instead of string-match[-p] when possible Dmitry Gutov
2023-03-26 23:35     ` Emanuel Berg
2023-03-27  4:58       ` Yuan Fu
2023-03-27 12:47     ` Mattias Engdegård
2023-03-29 15:23   ` Robert Pluim
2023-03-29 15:34     ` Mattias Engdegård
2023-03-29 15:54       ` Robert Pluim

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.