Skip to content

Commit

Permalink
Call MapFast in the devirtualised code path (not taken yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-hodgson authored Jul 11, 2024
1 parent 3f38d80 commit 3021b8f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Pidgin/Parser.Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ Parser<TToken, T1> parser1
}
}

// todo: devirtualise the remaining (generated) IMapParsers
internal interface IMapParser<TToken, T> : IParser<TToken, T>
{
Parser<TToken, U> MapFast<U>(Func<T, U> func);
}

internal sealed class Map1ParserFactory<TToken, T1, R>(Func<T1, R> func)
: IUnboxer<TToken, T1, BoxParser<TToken, R>>
: IUnboxer<TToken, T1, Parser<TToken, R>>
{
public BoxParser<TToken, R> Unbox<Next>(BoxParser<TToken, T1>.Of<Next> box)
public Parser<TToken, R> Unbox<Next>(BoxParser<TToken, T1>.Of<Next> box)
where Next : IParser<TToken, T1>
=> BoxParser<TToken, R>.Create(new Map1Parser<Next, TToken, T1, R>(func, box));
/* `m` is typically a boxed value type, we're building parsers anyway */
=> box.Value is IMapParser<TToken, T1> m
? m.MapFast(func)
: BoxParser<TToken, R>.Create(new Map1Parser<Next, TToken, T1, R>(func, box));
}

internal readonly struct Map1Parser<Next, TToken, T1, R> : IMapParser<TToken, R>
Expand Down

0 comments on commit 3021b8f

Please sign in to comment.