Skip to content

Commit b649e5c

Browse files
committed
Minor performance optimization
* Minor performance optimization for at rule check.
1 parent 7a4d9a8 commit b649e5c

File tree

8 files changed

+45
-20
lines changed

8 files changed

+45
-20
lines changed

dist/less.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,12 @@
29522952
skipWhitespace(1);
29532953
return tok;
29542954
};
2955+
parserInput.$peekChar = function (tok) {
2956+
if (input.charAt(parserInput.i) !== tok) {
2957+
return null;
2958+
}
2959+
return tok;
2960+
};
29552961
parserInput.$str = function (tok) {
29562962
var tokLength = tok.length;
29572963
// https://jsperf.com/string-startswith/21
@@ -4910,11 +4916,13 @@
49104916
debugInfo = getDebugInfo(index);
49114917
}
49124918
parserInput.save();
4913-
if (parserInput.$str('@media')) {
4914-
return this.prepareAndGetNestableAtRule(tree.Media, index, debugInfo, MediaSyntaxOptions);
4915-
}
4916-
if (parserInput.$str('@container')) {
4917-
return this.prepareAndGetNestableAtRule(tree.Container, index, debugInfo, ContainerSyntaxOptions);
4919+
if (parserInput.$peekChar('@')) {
4920+
if (parserInput.$str('@media')) {
4921+
return this.prepareAndGetNestableAtRule(tree.Media, index, debugInfo, MediaSyntaxOptions);
4922+
}
4923+
if (parserInput.$str('@container')) {
4924+
return this.prepareAndGetNestableAtRule(tree.Container, index, debugInfo, ContainerSyntaxOptions);
4925+
}
49184926
}
49194927
parserInput.restore();
49204928
},

dist/less.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/less.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/less/dist/less.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,12 @@
29522952
skipWhitespace(1);
29532953
return tok;
29542954
};
2955+
parserInput.$peekChar = function (tok) {
2956+
if (input.charAt(parserInput.i) !== tok) {
2957+
return null;
2958+
}
2959+
return tok;
2960+
};
29552961
parserInput.$str = function (tok) {
29562962
var tokLength = tok.length;
29572963
// https://jsperf.com/string-startswith/21
@@ -4910,11 +4916,13 @@
49104916
debugInfo = getDebugInfo(index);
49114917
}
49124918
parserInput.save();
4913-
if (parserInput.$str('@media')) {
4914-
return this.prepareAndGetNestableAtRule(tree.Media, index, debugInfo, MediaSyntaxOptions);
4915-
}
4916-
if (parserInput.$str('@container')) {
4917-
return this.prepareAndGetNestableAtRule(tree.Container, index, debugInfo, ContainerSyntaxOptions);
4919+
if (parserInput.$peekChar('@')) {
4920+
if (parserInput.$str('@media')) {
4921+
return this.prepareAndGetNestableAtRule(tree.Media, index, debugInfo, MediaSyntaxOptions);
4922+
}
4923+
if (parserInput.$str('@container')) {
4924+
return this.prepareAndGetNestableAtRule(tree.Container, index, debugInfo, ContainerSyntaxOptions);
4925+
}
49184926
}
49194927
parserInput.restore();
49204928
},

packages/less/dist/less.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/less/dist/less.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/less/src/less/parser/parser-input.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ export default () => {
149149
return tok;
150150
};
151151

152+
parserInput.$peekChar = tok => {
153+
if (input.charAt(parserInput.i) !== tok) {
154+
return null;
155+
}
156+
return tok;
157+
};
158+
152159
parserInput.$str = tok => {
153160
const tokLength = tok.length;
154161

packages/less/src/less/parser/parser.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,12 +1845,14 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
18451845
}
18461846
parserInput.save();
18471847

1848-
if (parserInput.$str('@media')) {
1849-
return this.prepareAndGetNestableAtRule(tree.Media, index, debugInfo, MediaSyntaxOptions);
1850-
}
1851-
1852-
if (parserInput.$str('@container')) {
1853-
return this.prepareAndGetNestableAtRule(tree.Container, index, debugInfo, ContainerSyntaxOptions);
1848+
if (parserInput.$peekChar('@')) {
1849+
if (parserInput.$str('@media')) {
1850+
return this.prepareAndGetNestableAtRule(tree.Media, index, debugInfo, MediaSyntaxOptions);
1851+
}
1852+
1853+
if (parserInput.$str('@container')) {
1854+
return this.prepareAndGetNestableAtRule(tree.Container, index, debugInfo, ContainerSyntaxOptions);
1855+
}
18541856
}
18551857

18561858
parserInput.restore();

0 commit comments

Comments
 (0)