Commit e5e08cc
committed
Improved stateful surpasses() impl that hews closely to the NonISODateSurpasses spec
This is not ready to go, but I wanted to get some feedback.
Most of the following will not make sense until one has seen the code.
- The priority here is to stick to the spec, and avoid recalculation.
There are some clumsy aspects, like the need for the caller to
invoke the checker in a specific way:
1. Large fields to small fields.
2. Before moving from field A to field B, make a final
call with the computed value of field A, to set the internal
state correctly.
3. Caller maintains their own y/m/w/d.
I tried to work around unicode-org#2 and unicode-org#3, but couldn't come up with
anything clean. It seems like the current approach is a good
compromise.
- For the debug assertions, clippy complained that I was calling
a mut function. This is actually ok, because the object
is reset to a new state immediately afterwards. The workaround
to the clippy warning is expensive, but should be ok because it's
just for debug. I tried other approaches but didn't get anything
else to work. Adding an "allow" directive didn't work because
debug_assert! is a macro.
- There is now no in-library usage of surpasses(). All the testing
for that was via until() as far as I can tell. The work item is
to add test coverage for surpasses(), and once that looks good,
I will refactor surpasses() to use the stateful checker, to
optimize performance and eliminate duplicate code.1 parent 0cc1365 commit e5e08cc
1 file changed
+230
-169
lines changed
0 commit comments