Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update data structure #155

Merged
merged 1 commit into from
Mar 27, 2023
Merged

chore: Update data structure #155

merged 1 commit into from
Mar 27, 2023

Conversation

kitten
Copy link
Member

@kitten kitten commented Mar 26, 2023

Summary

This updates the internal data structures of SignalKind signals to be backwards compatible but simpler. This results in a slight speedup in V8.

// before
export function start<T>(talkback: TalkbackFn): Start<T> {
  const box: any = [talkback];
  box.tag = SignalKind.Start;
  return box;
}

export function push<T>(value: T): Push<T> {
  const box: any = [value];
  box.tag = SignalKind.Push;
  return box;
}

// after
export function start<T>(talkback: TalkbackFn): Start<T> {
  return {
    tag: SignalKind.Start,
    0: talkback,
  } as Start<T>;
}

export function push<T>(value: T): Push<T> {
  return {
    tag: SignalKind.Push,
    0: value,
  } as Push<T>;
}

These are backwards-compatible because Wonka code (even before the current major, is only ever guaranteed to access [0] or .tag but never any array primitives.

Set of changes

  • Replace start() and push() primitives

@kitten kitten merged commit 26e15cf into main Mar 27, 2023
@kitten kitten deleted the chore/update-data-structures branch March 27, 2023 13:47
@github-actions github-actions bot mentioned this pull request Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants