[m-rev.] for review: improve dir./

Peter Wang novalazy at gmail.com
Mon Sep 11 12:59:40 AEST 2023


On Mon, 11 Sep 2023 12:11:41 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> On 2023-09-11 11:42 +10:00 AEST, "Peter Wang" <novalazy at gmail.com> wrote:
> >> +:- pred is_path_string_canonical_loop(string::in, int::in, canon_prev_char::in)
> >> +    is semidet.
> >> +
> >> +is_path_string_canonical_loop(Path, CurIndex, PrevChar) :-
> >> +    ( if string.index_next(Path, CurIndex, NextIndex, Char) then
> > 
> > The problem is string.index_next incurs a call to string.length for each
> > call, unlike string.unsafe_index_next.
> 
> I forgot about that. We don't want those duplicated calls.
> 
> > It's quite easy to use
> > unsafe_index_next safely, though.
> 
> Do you mean code like what the calls to index_next replaced,
> or something else?
> 

I mean that depite the name, unsafe_index_next is not full of footguns
(at least, I don't think so). The usual pattern is to start from index 0,
then iterate through the string using the index returned by the previous
call to unsafe_index_next; that's safe.

Peter


More information about the reviews mailing list