avoid unnecessary allocation of empty string in common case of regexp-.../full result

This commit is contained in:
Matthew Flatt 2010-04-15 11:26:37 -04:00
parent 249a9e38f7
commit 406a38148d

View File

@ -116,6 +116,8 @@ static unsigned char *extract_regstart(rxpos scan, int *_anch);
static int check_and_propagate_depends(void);
static int merge_tables(Scheme_Hash_Table *dest, Scheme_Hash_Table *src);
READ_ONLY static Scheme_Object *empty_byte_string;
#define FAIL(m) { regcomperror(m); return 0; }
static void
@ -5183,6 +5185,9 @@ static Scheme_Object *gen_compare(char *name, int pos,
|| (endp[0] - minpos < last_bytes_count))
last_bytes_count = endp[0] - minpos;
if (!last_bytes_count) {
last_bytes_str = empty_byte_string;
} else {
frompos = endp[0] - last_bytes_count;
tooffset = 0;
@ -5203,6 +5208,7 @@ static Scheme_Object *gen_compare(char *name, int pos,
full_s + frompos,
last_bytes_count);
}
}
if (pos > 1) {
/* pos == 2 => just get true or false */
@ -5737,6 +5743,9 @@ void scheme_regexp_initialize(Scheme_Env *env)
GC_REG_TRAV(scheme_rt_regwork, mark_regwork);
#endif
REGISTER_SO(empty_byte_string);
empty_byte_string = scheme_alloc_byte_string(0, 0);
GLOBAL_PRIM_W_ARITY("byte-regexp", make_regexp, 1, 1, env);
GLOBAL_PRIM_W_ARITY("regexp", make_utf8_regexp, 1, 1, env);
GLOBAL_PRIM_W_ARITY("byte-pregexp", make_pregexp, 1, 1, env);