Skip to content

Commit aa5d667

Browse files
Speed up stringifyNumber (#1717)
I'm currently profiling my build setup and noticed that `stringifyNumber` pops up here and there. Instead of going with the double regex replace approach, we'll go with the faster approach in `removeLeadingZero`. In total the changes in this PR speed up the build by about `0.9s` in my project. <img width="798" alt="stringifyNumber" src="https://user-images.githubusercontent.com/1062408/204154146-ce67d0c9-faf2-40a1-8186-8d34caea74a5.png">
1 parent c641da2 commit aa5d667

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/path.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { removeLeadingZero } = require('./svgo/tools');
4+
35
/**
46
* @typedef {import('./types').PathDataItem} PathDataItem
57
* @typedef {import('./types').PathDataCommand} PathDataCommand
@@ -249,7 +251,7 @@ const stringifyNumber = (number, precision) => {
249251
number = Math.round(number * ratio) / ratio;
250252
}
251253
// remove zero whole from decimal number
252-
return number.toString().replace(/^0\./, '.').replace(/^-0\./, '-.');
254+
return removeLeadingZero(number);
253255
};
254256

255257
/**

0 commit comments

Comments
 (0)