-
Notifications
You must be signed in to change notification settings - Fork 172
Add utility functions for string to integer conversions #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- add `is_upper_ascii()` and `to_upper_ascii()` - add `u32toa()`, `i32toa()`, `u64toa()`, `i64toa()` `u32toa_radix()`, `u64toa_radix()`, `i64toa_radix()` - use direct converters instead of `snprintf()` - copy NaN and Infinity directly in `js_dtoa1()` - optimize `js_number_toString()` for small ints - use `JS_NewStringLen()` instead of `JS_NewString()` when possible - add more precise conversion tests in microbench.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some compilers are not happy...
Yes, gcc 32-bit optimizes the naive copy loop beyond sanity (uses SIMD instructions) which causes reads beyond the array boundaries. I am investigating other approaches. WIP |
- move `is_be()` to cutils.h - use register shift variant for `u32toa` and `u64toa` - use length_loop variant for `u32toa_radix` and `u64toa_radix` - add extensive benchmark for integer conversion variants in tests/test_conv.c
I ran extensive benchmarks to test various methods to convert integers to strings in base 10 or others. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
is_upper_ascii()
andto_upper_ascii()
u32toa()
,i32toa()
,u64toa()
,i64toa()
u32toa_radix()
,u64toa_radix()
,i64toa_radix()
snprintf()
js_dtoa1()
js_number_toString()
for small intsJS_NewStringLen()
instead ofJS_NewString()
when possible