Request
In the Token class we always cache the string in to_string and also cache the string in to_string_view if it is the wrap around case for the circular buffer. However, the cost of maintaining this cached string is a string reset call when setting the token start/end positions. There are two cases to consider:
-
The Token string is accessed several times, in which case rebuilding it is expensive. However, the caller could just cache it themselves if this was the case.
-
The token string is accessed once, in which case there is no point to cache the string.
Also, in both cases, the wrap around case should happen so infrequently its not worth caching it.
Possible implementation
Remove the cached string and always compute the string if to_string or to_string_view is called.