[zeek/spicy] ba86ae: Change `hilti::rt::atoi_n` to take a `string_view`

0 views
Skip to first unread message

Benjamin Bannier

unread,
Jun 22, 2026, 5:00:14 AM (12 days ago) Jun 22
to spicy-...@zeek.org
Branch: refs/heads/topic/bbannier/atoi_n-rewrite
Home: https://github.com/zeek/spicy
Commit: ba86aeaacb4c6ba7ee197574319134e2bd6fbe63
https://github.com/zeek/spicy/commit/ba86aeaacb4c6ba7ee197574319134e2bd6fbe63
Author: Benjamin Bannier <benjamin...@corelight.com>
Date: 2026-06-22 (Mon, 22 Jun 2026)

Changed paths:
M hilti/runtime/include/util.h
M hilti/runtime/src/tests/util.cc
M hilti/runtime/src/types/bytes.cc
M hilti/runtime/src/util.cc
M hilti/toolchain/include/base/util.h
M hilti/toolchain/src/base/preprocessor.cc

Log Message:
-----------
Change `hilti::rt::atoi_n` to take a `string_view`

This function previously accepted and returned generic iterators. This
not only made calling it potentially error prone, but also lead to some
awkwardness in using its return value (e.g., use of iterator math to
decide whether anything was consumed). On the implementation side, it
also restricted what operations were possible on the passed iterators
which would make e.g., rewriting the function in terms of
`std::from_chars` harder than needed.

This patch changes the function to instead accept `std::string_view`
instead, and return the number of consumed bytes.


Commit: 01996ec4c25cd31f6ff7f5c09c46d2bb8c523f41
https://github.com/zeek/spicy/commit/01996ec4c25cd31f6ff7f5c09c46d2bb8c523f41
Author: Benjamin Bannier <benjamin...@corelight.com>
Date: 2026-06-22 (Mon, 22 Jun 2026)

Changed paths:
M hilti/runtime/include/util.h
M hilti/runtime/src/benchmarks/iteration.cc
M hilti/runtime/src/tests/bytes.cc
M hilti/runtime/src/tests/util.cc
M hilti/runtime/src/types/bytes.cc
M hilti/runtime/src/util.cc

Log Message:
-----------
Reimplement `hilti::rt::atoi_n` in terms of `std::from_chars`

This simplifies our implementation significantly, but also requires
changing existing behavior: now negative values parsed into a positive
type to not wrap around anymore, but instead raise an exception.

Looking at the runtime performance, this implementation is maybe about
~10% faster for very many digits, but up to 2x slower for single digit
numbers.


Compare: https://github.com/zeek/spicy/compare/b6a1f3fac231...01996ec4c25c

To unsubscribe from these emails, change your notification settings at https://github.com/zeek/spicy/settings/notifications
Reply all
Reply to author
Forward
0 new messages