diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-07-22 07:07:51 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-07-22 07:07:51 -0700 |
commit | 955fa5af407155124977adf8914f825423c21584 (patch) | |
tree | 49430c9f8b4b101b93c1dad2ed59915c62da1797 /lib.c | |
parent | ec566bdca6dc3d41c6a7e5342fdeeef9d10dab89 (diff) | |
download | txr-955fa5af407155124977adf8914f825423c21584.tar.gz txr-955fa5af407155124977adf8914f825423c21584.tar.bz2 txr-955fa5af407155124977adf8914f825423c21584.zip |
parser: remove some wasteful string object allocations.
* lib.c (int_str_wc): New function, made out of int_str.
This can be used by the parser to work with a wchar_t *
string without having to create a string object.
(int_str): Implemented in terms of int_str_wc.
* parser.l (grammar): Remove string_own calls from numerous
rule bodies that use int_str to return a number.
These rules now capture the wchar_t string, pass it to
int_str_wc and then immediately free it. Whereas string_own
allocates an extra object and leaves it to the garbage
collector.
* lex.yy.c.shipped: Regenerated.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -6817,10 +6817,9 @@ val str_ge(val astr, val bstr) return if2(cmp == zero || cmp == one, t); } -val int_str(val str, val base) +val int_str_wc(const wchar_t *wcs, val base) { val self = lit("int-str"); - const wchar_t *wcs = c_str(str, self); wchar_t *ptr; long value; cnum b = c_num(default_arg(base, num_fast(10)), self); @@ -6882,8 +6881,6 @@ val int_str(val str, val base) val bignum = make_bignum(); mp_err err = mp_read_radix(mp(bignum), wcs, b); - gc_hint(str); - if (err != MP_OKAY) return nil; @@ -6906,6 +6903,15 @@ val int_str(val str, val base) return bignum_from_long(value); } +val int_str(val str, val base) +{ + val self = lit("int-str"); + const wchar_t *wcs = c_str(str, self); + val out = int_str_wc(wcs, base); + gc_hint(str); + return out; +} + val flo_str_utf8(const char *str) { char *ptr; |