fengb / zCord

Zig ⚡ Discord API with zero allocations in the critical path
MIT License
55 stars 12 forks source link

Smarter `number(float)` buffer #6

Closed fengb closed 2 years ago

fengb commented 3 years ago

The code currently handles floats by using a 4096 buffer space. We can do better:

Thoughts on a limiting parser:

  1. Fill up the buffer until mantissa is full
  2. If mantissa is full, don't append into buffer. If we didn't see a decimal, keep accruing the digit overflow; this is going to append to the actual exponents.
  3. If we find e, treat the next set of digits as exponents.
  4. Toss this result weird monstrosity result into parseFloat

I believe parseFloat should handle all of these edge cases already, in which case it could possibly be adapted to understand a reader instead of just strings. So maybe we could push an update to stdlib.