diff options
| author | Damien George <damien.p.george@gmail.com> | 2015-02-08 01:57:40 +0000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2015-02-08 01:57:40 +0000 |
| commit | 7d414a1b52d193bab2c94cf56932e1eba23ba542 (patch) | |
| tree | 69f6840e4f825ffc1047fe7cb0f52eba27b20d86 /py/parsenumbase.c | |
| parent | 5f97aaeca4dc607a2d32e758c3ef6131ffb168a6 (diff) | |
py: Parse big-int/float/imag constants directly in parser.
Previous to this patch, a big-int, float or imag constant was interned
(made into a qstr) and then parsed at runtime to create an object each
time it was needed. This is wasteful in RAM and not efficient. Now,
these constants are parsed straight away in the parser and turned into
objects. This allows constants with large numbers of digits (so
addresses issue #1103) and takes us a step closer to #722.
Diffstat (limited to 'py/parsenumbase.c')
| -rw-r--r-- | py/parsenumbase.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/py/parsenumbase.c b/py/parsenumbase.c index cb524057f..31e4a9164 100644 --- a/py/parsenumbase.c +++ b/py/parsenumbase.c @@ -29,8 +29,10 @@ // find real radix base, and strip preceding '0x', '0o' and '0b' // puts base in *base, and returns number of bytes to skip the prefix mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base) { - (void)len; // TODO use given len? const byte *p = (const byte*)str; + if (len <= 1) { + goto no_prefix; + } unichar c = *(p++); if ((*base == 0 || *base == 16) && c == '0') { c = *(p++); @@ -57,10 +59,11 @@ mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base) { p -= 2; } } else { + p--; + no_prefix: if (*base == 0) { *base = 10; } - p--; } return p - (const byte*)str; } |
