[m-rev.] for post-commit review: optimize a test
Peter Wang
novalazy at gmail.com
Mon Jul 10 11:15:13 AEST 2023
On Mon, 10 Jul 2023 01:46:30 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> Make a test more efficient.
>
> library/string.builder.m:
> Add a predicate that tests whether the total length of the string
> implicit in a string builder is within a limit, or not.
>
> Add a function that returns that total length.
>
> NEWS.md:
> Announce the new predicate and function.
>
> compiler/parse_tree_out_term.m:
> Use the new predicate to optimize a test.
> +%---------------------%
> +
> + % Return the total length of the string that to_string would return,
> + % without constructing that string (yet).
> + %
> + % Note that once you call this function, you cannot add any new entries
> + % to the given string builder state, because it loses its uniqueness.
> + %
> +:- func total_length(string.builder.state) = int.
The documentation should mention what it is counting.
string.length counts code units, so I suggest naming this function
total_code_points or count_code_points or num_code_points, etc.
Similarly for total_length_is_at_most.
Peter
More information about the reviews
mailing list