[前][次][番号順一覧][スレッド一覧]

ruby-changes:74213

From: S-H-GAMELINKS <ko1@a...>
Date: Sun, 23 Oct 2022 17:39:24 +0900 (JST)
Subject: [ruby-changes:74213] 1e06ef1328 (master): Introduce rb_memsearch_with_char_size function

https://git.ruby-lang.org/ruby.git/commit/?id=1e06ef1328

From 1e06ef1328880bf39a7e6d757678be619c21f0c1 Mon Sep 17 00:00:00 2001
From: S-H-GAMELINKS <gamelinks007@g...>
Date: Sat, 22 Oct 2022 18:26:53 +0900
Subject: Introduce rb_memsearch_with_char_size function

---
 re.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/re.c b/re.c
index f52492245e..d66f389c6f 100644
--- a/re.c
+++ b/re.c
@@ -220,11 +220,16 @@ rb_memsearch_qs_utf8(const unsigned char *xs, long m, const unsigned char *ys, l https://github.com/ruby/ruby/blob/trunk/re.c#L220
     return -1;
 }
 
+enum char_size
+{
+    WCHAR_SIZE = 2,
+    QCHAR_SIZE = 4
+};
+
 static inline long
-rb_memsearch_wchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
+rb_memsearch_with_char_size(const unsigned char *xs, long m, const unsigned char *ys, long n, enum char_size char_size)
 {
     const unsigned char *x = xs, x0 = *xs, *y = ys;
-    enum {char_size = 2};
 
     for (n -= m; n >= 0; n -= char_size, y += char_size) {
         if (x0 == *y && memcmp(x+1, y+1, m-1) == 0)
@@ -234,16 +239,15 @@ rb_memsearch_wchar(const unsigned char *xs, long m, const unsigned char *ys, lon https://github.com/ruby/ruby/blob/trunk/re.c#L239
 }
 
 static inline long
-rb_memsearch_qchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
+rb_memsearch_wchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
 {
-    const unsigned char *x = xs, x0 = *xs, *y = ys;
-    enum {char_size = 4};
+    return rb_memsearch_with_char_size(xs, m, ys, n, WCHAR_SIZE);
+}
 
-    for (n -= m; n >= 0; n -= char_size, y += char_size) {
-        if (x0 == *y && memcmp(x+1, y+1, m-1) == 0)
-            return y - ys;
-    }
-    return -1;
+static inline long
+rb_memsearch_qchar(const unsigned char *xs, long m, const unsigned char *ys, long n)
+{
+    return rb_memsearch_with_char_size(xs, m, ys, n, QCHAR_SIZE);
 }
 
 long
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]