Closed Whiteknight closed 12 months ago
I have made a number of improvements to this mechanism for v5, but the reality is that very few parsers make use of it. I will continue to keep an eye on it, and consider removing it for subsequent releases.
SuccessResult takes a ResultData struct, which wraps an object
. The object can either be a single data item or an array of objects of other data items to search through. In either case, this mechanism is pretty speedy and I don't think it requires further reevaluation at this time.
The .TryGetData method requires many results to include a newly-allocated array or list of objects, but the user frequently will not access this information. This means that we are allocating a new array when we allocate a new result (in parsers which use result data). but because IResult is not disposable (and I do not want to add and enforce it) we cannot rent these data arrays from the ArrayPool because there's no way to return them when we're done.
We could create a SuccessResult variant which takes a single object, and returns that object if it is T. If all our parsers which use result data return only a single item, this might work.
We could remove .TryGetData() entirely. Parsers which need to return data can instead get a variant which returns it. For example,
IParser<char, string> Regex()
could add a variantIParser<char, RegexMatch> RegexCapture()
.There's a lot of extra allocations flying around here, and I want to make sure we keep them under control.