Skip to content

Commit 136a459

Browse files
committed
Optimized the clean() code to no longer use .trim() (speeds up working against long HTML in IE). Fixes jquery#4037.
1 parent 6b938e1 commit 136a459

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/core.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ jQuery.extend({
855855
});
856856

857857
// Trim whitespace, otherwise indexOf won't work as expected
858-
var tags = jQuery.trim( elem ).toLowerCase();
858+
var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
859859

860860
var wrap =
861861
// option or optgroup
@@ -895,11 +895,12 @@ jQuery.extend({
895895
if ( !jQuery.support.tbody ) {
896896

897897
// String was a <table>, *may* have spurious <tbody>
898-
var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
899-
div.firstChild && div.firstChild.childNodes :
898+
var hasBody = /<tbody/i.test(elem),
899+
tbody = !tags.indexOf("<table") && !hasBody ?
900+
div.firstChild && div.firstChild.childNodes :
900901

901902
// String was a bare <thead> or <tfoot>
902-
wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
903+
wrap[1] == "<table>" && !hasBody ?
903904
div.childNodes :
904905
[];
905906

0 commit comments

Comments
 (0)