[pcre-dev] A tweak for the NO_RECURSE option

Góra strony
Delete this message
Autor: Graycode
Data:  
Dla: pcre-dev
Temat: [pcre-dev] A tweak for the NO_RECURSE option
When PCRE is compiled with NO_RECURSE then it uses allocated heap
storage instead of recursion with the stack.

The majority of expressions that I use do not require recursion and
perhaps neither does a large portion of the PCRE testdata suite. Yet
an initial heap allocation is currently always done every time. These
can add up because the match() function may be invoked multiple times
when pcre_exec() is processing a single expression.

With the modification shown below, the stack is used for the initial
frame and only recursions are allocated from the heap if needed. A
heap allocation would no longer be needed every time the match()
process is invoked.


--- pcre_exec.c  (version 8.21-RC1)
+++ pcre_exec.c  (working copy)
@@ -328,7 +328,8 @@
   {\
   heapframe *oldframe = frame;\
   frame = oldframe->Xprevframe;\
-  (pcre_stack_free)(oldframe);\
+  if (oldframe != &frame_zero)\
+    (pcre_stack_free)(oldframe);\
   if (frame != NULL)\
     {\
     rrc = ra;\
@@ -485,8 +486,9 @@
 heap whenever RMATCH() does a "recursion". See the macro definitions above. */


 #ifdef NO_RECURSE
-heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));
-if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
+heapframe frame_zero;
+heapframe *frame = &frame_zero;
+
 frame->Xprevframe = NULL;            /* Marks the top level */


/* Copy in the original argument variables */



Regards,
Graycode