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

refactor(cleanupNumericValues): improve how viewbox is split #2044

Closed
wants to merge 1 commit into from

Conversation

SethFalco
Copy link
Member

@SethFalco SethFalco commented Jun 30, 2024

After fixing a bug in cleanupNumericValues, a comment proposed that we handle this slightly differently.

This is a minor refactor/optimization of cleanupNumericValues. The idea is that if we're going to use a regular expression anyway, we might as well get the regex to do all the work to avoid filtering later.

const data = [
  '0 0 100 100',
  ' 0 0 100 100 ',
  '  0  0  100  100  ',
  ' 0  0  0.5  .5 ',
  '20.000001 -19.99999 17.123456 70.708090',
];

const splitV1 = (viewbox) => {
  return viewbox.split(/\s,?\s*|,\s*/g).filter(v => v.length != 0);
};
// v1 x 1,771,127 ops/sec ±0.49% (98 runs sampled)

const splitV5 = (viewbox) => {
  return viewbox.split(/\b(?:\s+,?|\s*,)\s*(?=\S)/g);
};
// v6 x 1,873,086 ops/sec ±0.39% (100 runs sampled)

Related

@SethFalco SethFalco force-pushed the chore-cleanup-numeric-values branch from 3489bf5 to 52d6750 Compare June 30, 2024 11:50
@SethFalco SethFalco closed this Jun 30, 2024
@SethFalco SethFalco deleted the chore-cleanup-numeric-values branch June 30, 2024 12:23
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.

None yet

1 participant