@samitouri / QOS-React-2 / commits / 6950a8418c

Use faster cached regexps for tests in setInnerHTML

Andreas Svensson committed Jul 19, 2014 at 21:00 UTC 6950a8418c54178dc373700d101cac420d79e7c5
1 file changed +5 -7
src/browser/ui/dom/setInnerHTML.js
+5 -7
@@ -20,6 +20,9 @@
20
21 var ExecutionEnvironment = require('ExecutionEnvironment');
22
23 +var WHITESPACE_TEST = /^[ \r\n\t\f]/;
24 +var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
25 +
26 /**
27 * Set the innerHTML property of a node, ensuring that whitespace is preserved
28 * even in IE8.
@@ -56,13 +59,8 @@ if (ExecutionEnvironment.canUseDOM) {
59 // thin air on IE8, this only happens if there is no visible text
60 // in-front of the non-visible tags. Piggyback on the whitespace fix
61 // and simply check if any non-visible tags appear in the source.
59 - if (html.match(/^[ \r\n\t\f]/) ||
60 - html[0] === '<' && (
61 - html.indexOf('<noscript') !== -1 ||
62 - html.indexOf('<script') !== -1 ||
63 - html.indexOf('<style') !== -1 ||
64 - html.indexOf('<meta') !== -1 ||
65 - html.indexOf('<link') !== -1)) {
62 + if (WHITESPACE_TEST.test(html) ||
63 + html[0] === '<' && NONVISIBLE_TEST.test(html)) {
64 // Recover leading whitespace by temporarily prepending any character.
65 // \uFEFF has the potential advantage of being zero-width/invisible.
66 node.innerHTML = '\uFEFF' + html;