emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter a7042fa051 4/7: New function fast_c_string_match and


From: Yuan Fu
Subject: feature/tree-sitter a7042fa051 4/7: New function fast_c_string_match and fast_c_string_match_internal
Date: Wed, 9 Nov 2022 18:52:04 -0500 (EST)

branch: feature/tree-sitter
commit a7042fa051c69b8c647fce3ec52b74974b5ea2be
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    New function fast_c_string_match and fast_c_string_match_internal
    
    Generalize fast_c_string_match_ignore_case into
    fast_c_string_match_internal.  And Make fast_c_string and
    fast_c_string_match_ignore_case use fast_c_string_match_internal.
    
    * src/lisp.h (fast_c_string_match_internal)
    (fast_c_string_match): New declaration.
    (fast_c_string_match_ignore_case): Change to thin wrapper.
    * src/search.c (fast_c_string_match_internal): New function.
---
 src/lisp.h   | 19 +++++++++++++++++--
 src/search.c | 20 ++++++++++++++------
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/lisp.h b/src/lisp.h
index 1e41e2064c..9f497d9227 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4757,6 +4757,8 @@ extern void update_search_regs (ptrdiff_t oldstart,
 extern void record_unwind_save_match_data (void);
 extern ptrdiff_t fast_string_match_internal (Lisp_Object, Lisp_Object,
                                             Lisp_Object);
+extern ptrdiff_t fast_c_string_match_internal (Lisp_Object, const char *,
+                                              ptrdiff_t, Lisp_Object);
 
 INLINE ptrdiff_t
 fast_string_match (Lisp_Object regexp, Lisp_Object string)
@@ -4770,8 +4772,21 @@ fast_string_match_ignore_case (Lisp_Object regexp, 
Lisp_Object string)
   return fast_string_match_internal (regexp, string, Vascii_canon_table);
 }
 
-extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
-                                                 ptrdiff_t);
+INLINE ptrdiff_t
+fast_c_string_match (Lisp_Object regexp,
+                    const char *string, ptrdiff_t len)
+{
+  return fast_c_string_match_internal (regexp, string, len, Qnil);
+}
+
+INLINE ptrdiff_t
+fast_c_string_match_ignore_case (Lisp_Object regexp,
+                                const char *string, ptrdiff_t len)
+{
+  return fast_c_string_match_internal (regexp, string, len,
+                                      Vascii_canon_table);
+}
+
 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
                                   ptrdiff_t, ptrdiff_t, Lisp_Object);
 extern ptrdiff_t find_newline1 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
diff --git a/src/search.c b/src/search.c
index b5d6a442c0..bd1adbbe09 100644
--- a/src/search.c
+++ b/src/search.c
@@ -496,19 +496,27 @@ fast_string_match_internal (Lisp_Object regexp, 
Lisp_Object string,
   return val;
 }
 
-/* Match REGEXP against STRING, searching all of STRING ignoring case,
-   and return the index of the match, or negative on failure.
-   This does not clobber the match data.
+/* Match REGEXP against STRING, searching all of STRING and return the
+   index of the match, or negative on failure.  This does not clobber
+   the match data.  Table is a canonicalize table for ignoring case,
+   or nil for none.
+
    We assume that STRING contains single-byte characters.  */
 
 ptrdiff_t
-fast_c_string_match_ignore_case (Lisp_Object regexp,
-                                const char *string, ptrdiff_t len)
+fast_c_string_match_internal (Lisp_Object regexp,
+                             const char *string, ptrdiff_t len,
+                             Lisp_Object table)
 {
+  /* FIXME: This is expensive and not obviously correct when it makes
+     a difference. I.e., no longer "fast", and may hide bugs.
+     Something should be done about this.  */
   regexp = string_make_unibyte (regexp);
+  /* Record specpdl index because freeze_pattern pushes an
+     unwind-protect on the specpdl.  */
   specpdl_ref count = SPECPDL_INDEX ();
   struct regexp_cache *cache_entry
-    = compile_pattern (regexp, 0, Vascii_canon_table, 0, 0);
+    = compile_pattern (regexp, 0, table, 0, 0);
   freeze_pattern (cache_entry);
   re_match_object = Qt;
   ptrdiff_t val = re_search (&cache_entry->buf, string, len, 0, len, 0);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]