Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/lib/sort.js

Issue 125733002: Add vulcanize to tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/lib/sort.js
diff --git a/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/lib/sort.js b/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/lib/sort.js
new file mode 100644
index 0000000000000000000000000000000000000000..03ac2556ad3ff7ab3b76a7b334554d8629c48fad
--- /dev/null
+++ b/tools/vulcanize/node_modules/vulcanize/node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/lib/sort.js
@@ -0,0 +1,37 @@
+module.exports = sortByProcedure;
+
+/*
+ sort the parts of the passed selector,
+ as there is potential for optimization
+ (some types of selectors are faster than others)
+*/
+
+var procedure = {
+ __proto__: null,
+ universal: 5, //should be last so that it can be ignored
+ tag: 3, //very quick test
+ attribute: 1, //can be faster than class
+ pseudo: 0, //can be pretty expensive (especially :has)
+
+ //everything else shouldn't be moved
+ descendant: -1,
+ child: -1,
+ sibling: -1,
+ adjacent: -1
+};
+
+function sortByProcedure(arr){
+ //TODO sort individual attribute selectors
+ for(var i = 1; i < arr.length; i++){
+ var procNew = procedure[arr[i].type];
+
+ if(procNew !== -1){
+ for(var j = i - 1; j >= 0 && procNew < procedure[arr[j].type]; j--){
+ var tmp = arr[j + 1];
+ arr[j + 1] = arr[j];
+ arr[j] = tmp;
+ }
+ }
+ }
+ return arr;
+}

Powered by Google App Engine
This is Rietveld 408576698