Skip to content

Commit 71fe25c

Browse files
wartmanmgibson042
authored andcommitted
Core: Avoid unnecessary pre-qSA DOM manipulation
Fixes gh-430 Closes gh-431
1 parent f7eb85b commit 71fe25c

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

dist/sizzle.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Released under the MIT license
77
* https://js.foundation/
88
*
9-
* Date: 2018-10-20
9+
* Date: 2018-11-04
1010
*/
1111
(function( window ) {
1212

@@ -132,6 +132,8 @@ var i,
132132

133133
rsibling = /[+~]/,
134134

135+
rcomplex = new RegExp(whitespace + "|>"),
136+
135137
// CSS escapes
136138
// http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
137139
runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
@@ -304,20 +306,26 @@ function Sizzle( selector, context, results, seed ) {
304306
// Exclude object elements
305307
} else if ( context.nodeName.toLowerCase() !== "object" ) {
306308

307-
// Capture the context ID, setting it first if necessary
308-
if ( (nid = context.getAttribute( "id" )) ) {
309-
nid = nid.replace( rcssescape, fcssescape );
309+
// The workaround is only necessary if the selector
310+
// contains child or descendant combinators.
311+
if ( !rcomplex.test( selector ) ) {
312+
newSelector = selector;
310313
} else {
311-
context.setAttribute( "id", (nid = expando) );
312-
}
314+
// Capture the context ID, setting it first if necessary
315+
if ( (nid = context.getAttribute( "id" )) ) {
316+
nid = nid.replace( rcssescape, fcssescape );
317+
} else {
318+
context.setAttribute( "id", (nid = expando) );
319+
}
313320

314-
// Prefix every selector in the list
315-
groups = tokenize( selector );
316-
i = groups.length;
317-
while ( i-- ) {
318-
groups[i] = "#" + nid + " " + toSelector( groups[i] );
321+
// Prefix every selector in the list
322+
groups = tokenize( selector );
323+
i = groups.length;
324+
while ( i-- ) {
325+
groups[i] = "#" + nid + " " + toSelector( groups[i] );
326+
}
327+
newSelector = groups.join( "," );
319328
}
320-
newSelector = groups.join( "," );
321329

322330
// Expand context for sibling selectors
323331
newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||

0 commit comments

Comments
 (0)