Skip to content

rule candidate: restkeep — unread String suffix stored again while walking it #102

Description

@noah-emp

Category

suspicious

Shape

A recursive String stepper puts the unread suffix into a returned constructor field and also passes that same suffix as the walk argument (or stores it again in the next state). Every step then keeps an extra copy of the rest of the input.

Prefer returning a mode that means "resume on the suffix already in hand" without embedding that suffix a second time.

Bad

type Mode is Data:
  MDone{saved: String}

def step(rest: String) -> Mode:
  match rest:
    case SNil{}:
      MDone{rest}
    case SCon{_', t}:
      step(t)

Good

type Mode is Data:
  MRest{}

def step(rest: String) -> (Mode & String):
  match rest:
    case SNil{}:
      (MRest{}, rest)
    case SCon{_', t}:
      step(t)

(or thread rest only as the walk argument and leave it out of Mode)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsuspiciousProbably a slip / perf smell

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions