return 1;
}
-/*
- internal checking function used by both grammar_check and grammar_fast_check functions
-*/
-static int _grammar_check (grammar id, const byte *text, byte **prod, unsigned int *size,
- unsigned int estimate_prod_size, int use_fast_path)
-{
- dict *di = NULL;
+int
+grammar_fast_check (grammar id,
+ const byte *text,
+ byte **prod,
+ unsigned int *size,
+ unsigned int estimate_prod_size)
+{
+ dict *di = NULL;
int index = 0;
+ regbyte_ctx *rbc = NULL;
+ bytepool *bp = NULL;
+ int _P = 0;
clear_last_error ();
*prod = NULL;
*size = 0;
- if (use_fast_path)
- {
- regbyte_ctx *rbc = NULL;
- bytepool *bp = NULL;
- int _P = 0;
-
- bytepool_create (&bp, estimate_prod_size);
- if (bp == NULL)
- return 0;
-
- if (fast_match (di, text, &index, di->m_syntax, &_P, bp, 0, &rbc) != mr_matched)
- {
- bytepool_destroy (&bp);
- free_regbyte_ctx_stack (rbc, NULL);
- return 0;
- }
-
- free_regbyte_ctx_stack (rbc, NULL);
-
- *prod = bp->_F;
- *size = _P;
- bp->_F = NULL;
- bytepool_destroy (&bp);
- }
- else
- {
- regbyte_ctx *rbc = NULL;
- barray *ba = NULL;
-
- barray_create (&ba);
- if (ba == NULL)
- return 0;
-
- if (match (di, text, &index, di->m_syntax, &ba, 0, &rbc) != mr_matched)
- {
- barray_destroy (&ba);
- free_regbyte_ctx_stack (rbc, NULL);
- return 0;
- }
+ bytepool_create (&bp, estimate_prod_size);
+ if (bp == NULL)
+ return 0;
- free_regbyte_ctx_stack (rbc, NULL);
+ if (fast_match (di, text, &index, di->m_syntax, &_P, bp, 0, &rbc) != mr_matched)
+ {
+ bytepool_destroy (&bp);
+ free_regbyte_ctx_stack (rbc, NULL);
+ return 0;
+ }
- *prod = (byte *) mem_alloc (ba->len * sizeof (byte));
- if (*prod == NULL)
- {
- barray_destroy (&ba);
- return 0;
- }
+ free_regbyte_ctx_stack (rbc, NULL);
- mem_copy (*prod, ba->data, ba->len * sizeof (byte));
- *size = ba->len;
- barray_destroy (&ba);
- }
+ *prod = bp->_F;
+ *size = _P;
+ bp->_F = NULL;
+ bytepool_destroy (&bp);
return 1;
}
-int grammar_fast_check (grammar id, const byte *text, byte **prod, unsigned int *size,
- unsigned int estimate_prod_size)
-{
- return _grammar_check (id, text, prod, size, estimate_prod_size, 1);
-}
-
int grammar_destroy (grammar id)
{
dict **di = &g_dicts;