emacs-diffs
[Top][All Lists]
Advanced

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

master d995429e7bc: Use SBYTES instead of strlen in treesit.c


From: Stefan Kangas
Subject: master d995429e7bc: Use SBYTES instead of strlen in treesit.c
Date: Mon, 22 Jul 2024 06:21:36 -0400 (EDT)

branch: master
commit d995429e7bc2bc5b5d87db45dbbaca121f8118e5
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    Use SBYTES instead of strlen in treesit.c
    
    * src/treesit.c (treesit_ensure_query_compiled)
    (Ftreesit_node_child_by_field_name, treesit_initialize_query):
    Use SBYTES instead of strlen.
---
 src/treesit.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/treesit.c b/src/treesit.c
index a420ef77b2d..c95a9fb9b01 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1310,9 +1310,7 @@ treesit_ensure_query_compiled (Lisp_Object query, 
Lisp_Object *signal_symbol,
   /* Create TSQuery.  */
   uint32_t error_offset;
   TSQueryError error_type;
-  char *treesit_source = SSDATA (source);
-  treesit_query = ts_query_new (treesit_lang, treesit_source,
-                               strlen (treesit_source),
+  treesit_query = ts_query_new (treesit_lang, SSDATA (source), SBYTES (source),
                                &error_offset, &error_type);
   if (treesit_query == NULL)
     {
@@ -2159,11 +2157,10 @@ Return nil if there is no such child.  If NODE is nil, 
return nil.  */)
   CHECK_STRING (field_name);
   treesit_initialize ();
 
-  char *name_str = SSDATA (field_name);
   TSNode treesit_node = XTS_NODE (node)->node;
   TSNode child
-    = ts_node_child_by_field_name (treesit_node, name_str,
-                                  strlen (name_str));
+    = ts_node_child_by_field_name (treesit_node, SSDATA (field_name),
+                                  SBYTES (field_name));
 
   if (ts_node_is_null (child))
     return Qnil;
@@ -2888,10 +2885,9 @@ treesit_initialize_query (Lisp_Object query, const 
TSLanguage *lang,
         or a cons.  */
       if (CONSP (query))
        query = Ftreesit_query_expand (query);
-      char *query_string = SSDATA (query);
       uint32_t error_offset;
       TSQueryError error_type;
-      *ts_query = ts_query_new (lang, query_string, strlen (query_string),
+      *ts_query = ts_query_new (lang, SSDATA (query), SBYTES (query),
                                &error_offset, &error_type);
       if (*ts_query == NULL)
        {



reply via email to

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