From 00e30bfcaab982c0f0a4193f13f280d035bfa151 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Tue, 22 Jun 2010 22:58:26 +0900 Subject: [PATCH] packing string data into symbol instead of consing an extra string object --- include/chibi/sexp.h | 5 +++-- sexp.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 69684c3b..a9c642e5 100644 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -206,7 +206,8 @@ struct sexp_struct { char data[]; } string; struct { - sexp string; + sexp_uint_t length; + char data[]; } symbol; struct { FILE *stream; @@ -569,7 +570,7 @@ SEXP_API sexp sexp_make_unsigned_integer(sexp ctx, sexp_luint_t x); #define sexp_string_ref(x, i) (sexp_make_character((unsigned char)sexp_string_data(x)[sexp_unbox_fixnum(i)])) #define sexp_string_set(x, i, v) (sexp_string_data(x)[sexp_unbox_fixnum(i)] = sexp_unbox_character(v)) -#define sexp_symbol_string(x) ((x)->value.symbol.string) +#define sexp_symbol_string(x) (x) #define sexp_port_stream(p) ((p)->value.port.stream) #define sexp_port_name(p) ((p)->value.port.name) diff --git a/sexp.c b/sexp.c index 75333dab..075553a1 100644 --- a/sexp.c +++ b/sexp.c @@ -87,7 +87,7 @@ static struct sexp_struct _sexp_type_specs[] = { _DEF_TYPE(SEXP_CHAR, 0, 0, 0, 0, 0, 0, 0, 0, "char", NULL), _DEF_TYPE(SEXP_BOOLEAN, 0, 0, 0, 0, 0, 0, 0, 0, "boolean", NULL), _DEF_TYPE(SEXP_PAIR, sexp_offsetof(pair, car), 2, 3, 0, 0, sexp_sizeof(pair), 0, 0, "pair", NULL), - _DEF_TYPE(SEXP_SYMBOL, sexp_offsetof(symbol, string), 1, 1, 0, 0, sexp_sizeof(symbol), 0, 0, "symbol", NULL), + _DEF_TYPE(SEXP_SYMBOL, 0, 0, 0, 0, 0, sexp_sizeof(symbol)+1, sexp_offsetof(symbol, length), 1, "symbol", NULL), _DEF_TYPE(SEXP_STRING, 0, 0, 0, 0, 0, sexp_sizeof(string)+1, sexp_offsetof(string, length), 1, "string", NULL), _DEF_TYPE(SEXP_VECTOR, sexp_offsetof(vector, data), 0, 0, sexp_offsetof(vector, length), 1, sexp_sizeof(vector), sexp_offsetof(vector, length), sizeof(sexp), "vector", NULL), _DEF_TYPE(SEXP_FLONUM, 0, 0, 0, 0, 0, sexp_sizeof(flonum), 0, 0, "real", NULL), @@ -790,9 +790,9 @@ sexp sexp_intern(sexp ctx, const char *str, sexp_sint_t len) { /* not found, make a new symbol */ sexp_gc_preserve1(ctx, sym); - sym = sexp_alloc_type(ctx, symbol, SEXP_SYMBOL); + sym = sexp_c_string(ctx, str, len); if (sexp_exceptionp(sym)) return sym; - sexp_symbol_string(sym) = sexp_c_string(ctx, str, len); + sexp_pointer_tag(sym) = SEXP_SYMBOL; sexp_push(ctx, sexp_context_symbols(ctx)[bucket], sym); sexp_gc_release1(ctx); return sym;