Skip to content

Possible alternative use of switch that might be fast enough #150

@RandalSchwartz

Description

@RandalSchwartz

You rewrote this to be faster:

  int fastParseOn(String buffer, int position) {
    final result = parseOn(Context(buffer, position));
    return switch (result) {
      Success(position: final position) => position,
      Failure() => -1
    };
  }

I wonder if this might have been fast enough to still use the switch:

  int fastParseOn(String buffer, int position) {
    final result = parseOn(Context(buffer, position));
    return switch (result) {
      final Success s => s.position,
      Failure _ => -1,
    };
  }

I understand that might work faster for sorting out types and mapping them to branches. I think Type() goes through a lot of extra work compared to Type _.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions