]> granicus.if.org Git - onig/commitdiff
use direct threaded code for GNU C
authorK.Kosako <kosako@sofnec.co.jp>
Wed, 6 Feb 2019 07:40:44 +0000 (16:40 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Thu, 28 Feb 2019 05:28:18 +0000 (14:28 +0900)
src/regcomp.c
src/regexec.c
src/regint.h

index 792485a6051e2ea9776c00190f184cf22b4afa90..48898336cde3afaf33076388043d5e5292adfeb4 100644 (file)
@@ -6128,6 +6128,8 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
 {
 #define OPS_INIT_SIZE  8
 
+  extern int onig_init_for_match_at(regex_t* reg);
+
   int r;
   Node*  root;
   ScanEnv  scan_env;
@@ -6271,6 +6273,13 @@ onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
   onig_print_compiled_byte_code_list(stderr, reg);
 #endif
 
+#ifdef USE_THREADED_CODE
+#ifdef USE_DIRECT_THREADED_CODE
+  /* opcode -> opaddr */
+  onig_init_for_match_at(reg);
+#endif
+#endif
+
  end:
   return r;
 
index 0ff86122dfc00cb60000364dda0aadee4e93a93f..be3c3874cc17dd9b4a5c1b2e0aff12a556f51ea1 100644 (file)
@@ -2367,9 +2367,6 @@ typedef struct {
 } posix_regmatch_t;
 
 
-#ifdef __GNUC__
-#define USE_THREADED_CODE
-#endif
 
 #ifdef USE_THREADED_CODE
 
@@ -2379,7 +2376,11 @@ typedef struct {
 #define DEFAULT_OP   /* L_DEFAULT: */
 #define NEXT_OP      sprev = sbegin; JUMP_OP
 #define JUMP_OP      GOTO_OP
+#ifdef USE_DIRECT_THREADED_CODE
+#define GOTO_OP      goto *(p->opaddr)
+#else
 #define GOTO_OP      goto *opcode_to_label[p->opcode]
+#endif
 #define BREAK_OP     /* Nothing */
 
 #else
@@ -2449,7 +2450,12 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
          const UChar* in_right_range, const UChar* sstart, UChar* sprev,
          MatchArg* msa)
 {
-  static Operation FinishCode[] = { { OP_FINISH } };
+
+#if defined(USE_THREADED_CODE) && defined(USE_DIRECT_THREADED_CODE)
+  static Operation FinishCode[] = { { {.opaddr=&&L_FINISH} } };
+#else
+  static Operation FinishCode[] = { { {OP_FINISH} } };
+#endif
 
 #ifdef USE_THREADED_CODE
   static const void *opcode_to_label[] = {
@@ -2584,6 +2590,22 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
   static unsigned int counter = 1;
 #endif
 
+#ifdef USE_THREADED_CODE
+#ifdef USE_DIRECT_THREADED_CODE
+  if (IS_NULL(msa)) {
+    for (i = 0; i < reg->ops_used; i++) {
+       const void* addr;
+       /* fprintf(stdout, "code: %d, ", p->opcode); */
+       addr = opcode_to_label[p->opcode];
+       p->opaddr = addr;
+       /* fprintf(stdout, "addr: %p\n", p->opaddr); */
+       p++;
+    }
+    return ONIG_NORMAL;
+  }
+#endif
+#endif
+
 #ifdef USE_CALLOUT
   msa->mp->match_at_call_counter++;
 #endif
@@ -3620,20 +3642,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
           fprintf(stderr, "EMPTY_CHECK_END: skip  id:%d, s:%p\n", (int )mem, s);
 #endif
         empty_check_found:
-          /* empty loop founded, skip next instruction */
-          switch (p->opcode) {
-          case OP_JUMP:
-          case OP_PUSH:
-          case OP_REPEAT_INC:
-          case OP_REPEAT_INC_NG:
-          case OP_REPEAT_INC_SG:
-          case OP_REPEAT_INC_NG_SG:
-            INC_OP;
-            break;
-          default:
-            goto unexpected_bytecode_error;
-            break;
-          }
+          INC_OP;
         }
       }
       JUMP_OUT;
@@ -4070,10 +4079,6 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
   STACK_SAVE;
   return ONIGERR_UNDEFINED_BYTECODE;
 
- unexpected_bytecode_error:
-  STACK_SAVE;
-  return ONIGERR_UNEXPECTED_BYTECODE;
-
 #ifdef USE_RETRY_LIMIT_IN_MATCH
  retry_limit_in_match_over:
   STACK_SAVE;
@@ -5372,6 +5377,18 @@ onig_get_used_stack_size_in_callout(OnigCalloutArgs* a, int* used_num, int* used
   return ONIG_NORMAL;
 }
 
+#ifdef USE_THREADED_CODE
+#ifdef USE_DIRECT_THREADED_CODE
+extern int
+onig_init_for_match_at(regex_t* reg)
+{
+  return match_at(reg, (const UChar* )NULL, (const UChar* )NULL,
+                  (const UChar* )NULL, (const UChar* )NULL, (UChar* )NULL,
+                  (MatchArg* )NULL);
+}
+#endif
+#endif
+
 
 /* builtin callout functions */
 
index d750a8d79c8a5bfc1d13e9c9ca0a645fa574d63b..f8ba3371ddfee99465d7e8204a603cf6aff4e089 100644 (file)
 #define PLATFORM_UNALIGNED_WORD_ACCESS
 #endif
 
+#ifdef __GNUC__
+#define USE_THREADED_CODE
+#endif
+
 /* config */
 /* spec. config */
 #define USE_CALL
@@ -63,6 +67,9 @@
 #define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE     /* /\n$/ =~ "\n" */
 #define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
 #define USE_RETRY_LIMIT_IN_MATCH
+#ifdef USE_THREADED_CODE
+#define USE_DIRECT_THREADED_CODE
+#endif
 
 /* internal config */
 #define USE_OP_PUSH_OR_JUMP_EXACT
@@ -791,7 +798,10 @@ typedef int ModeType;
 
 
 typedef struct {
-  enum OpCode opcode;
+  union {
+    enum OpCode opcode;
+    const void* opaddr;
+  };
   union {
     struct {
       UChar* s;