{"ScriptPreparationCode":"var NEWLINE = /\\x0d\\x0a|[\\x0a\\x0d\\u2028\\u2029]/gu;\r\n\r\nfunction splitRegex(str) {\r\n const strings = [];\r\n\r\n NEWLINE.lastIndex = 0;\r\n let prevIndex = 0;\r\n let match;\r\n\r\n while (match = NEWLINE.exec(str)) {\r\n if (match.index \u003E prevIndex) strings.push(str.substring(prevIndex, match.index));\r\n strings.push(match[0]);\r\n prevIndex = match.index \u002B match[0].length;\r\n NEWLINE.lastIndex = prevIndex;\r\n }\r\n\r\n if (prevIndex \u003C str.length) strings.push(str.substring(prevIndex, str.length));\r\n\r\n return strings;\r\n}\r\n\r\nfunction splitManual(str) {\r\n\tconst strings = [];\r\n\r\n\tconst cache1 = { i: -1 };\r\n\tconst cache2 = { i: -1 };\r\n\tconst cache3 = { i: -1 };\r\n\tconst cache4 = { i: -1 };\r\n\r\n\tlet position = 0;\r\n\twhile (position \u003C str.length) {\r\n\t\tif (cache1.i \u003C 0) {\r\n\t\t\tconst i = str.indexOf(\u0027\\n\u0027, position);\r\n\t\t\tcache1.i = i \u003C 0 ? str.length : i;\r\n\t\t}\r\n\t\tif (cache2.i \u003C 0) {\r\n\t\t\tconst i = str.indexOf(\u0027\\r\u0027, position);\r\n\t\t\tcache2.i = i \u003C 0 ? str.length : i;\r\n\t\t}\r\n\t\tif (cache3.i \u003C 0) {\r\n\t\t\tconst i = str.indexOf(\u0027\\u2028\u0027, position);\r\n\t\t\tcache3.i = i \u003C 0 ? str.length : i;\r\n\t\t}\r\n\t\tif (cache4.i \u003C 0) {\r\n\t\t\tconst i = str.indexOf(\u0027\\u2029\u0027, position);\r\n\t\t\tcache4.i = i \u003C 0 ? str.length : i;\r\n\t\t}\r\n\r\n\t\tlet winner = cache1;\r\n\t\tif (cache2.i \u003C winner.i) winner = cache2;\r\n\t\tif (cache3.i \u003C winner.i) winner = cache3;\r\n\t\tif (cache4.i \u003C winner.i) winner = cache4;\r\n\r\n\t\tconst index = winner.i;\r\n\t\tif (index === str.length) {\r\n\t\t\tstrings.push(str.substring(position, index));\r\n\t\t\tbreak;\r\n\t\t}\r\n\r\n\t\tlet length = 1;\r\n\t\tif (winner === cache2 \u0026\u0026 str[index \u002B 1] === \u0027\\n\u0027) {\r\n\t\t\tcache1.i = -1;\r\n\t\t\tlength = 2;\r\n\t\t}\r\n\r\n\t\tif (index \u003E position) {\r\n\t\t\tstrings.push(str.substring(position, index));\r\n\t\t}\r\n\t\tstrings.push(str.substring(index, index \u002B length));\r\n\r\n\t\tposition = index \u002B length;\r\n\t\twinner.i = -1;\r\n\t}\r\n\r\n\treturn strings;\r\n}\r\n\r\nvar NO_NEWLINE = \u0027foobarbaz!\u0027.repeat(1000);\r\nvar LAST_NEWLINE = \u0027foobarbaz!\u0027.repeat(1000) \u002B \u0027\\n\u0027;\r\nvar LAST_NEWLINE_WIN32 = \u0027foobarbaz!\u0027.repeat(1000) \u002B \u0027\\r\\n\u0027;\r\nvar LAST_NEWLINE_UNICODE = \u0027foobarbaz!\u0027.repeat(1000) \u002B \u0027\\u2029\u0027;\r\nvar MANY_NEWLINES = \u0027foobarbaz\\n\u0027.repeat(1000);\r\nvar MANY_NEWLINES_WIN32 = \u0027foobarbaz\\r\\n\u0027.repeat(1000);\r\nvar MANY_NEWLINES_UNICODE = \u0027foobarbaz\\u2029\u0027.repeat(1000);\r\n\r\n// Side-effect to prevent code from being optimized away\r\nwindow.result = 0;\r\nvar register = (results) =\u003E { window.result \u002B= (results[results.length - 1] || \u0027\u0027).slice(-1).charCodeAt(0); };\r\n","TestCases":[{"Name":"regex","Code":"register(splitRegex(NO_NEWLINE));\r\nregister(splitRegex(LAST_NEWLINE));\r\nregister(splitRegex(LAST_NEWLINE_WIN32));\r\nregister(splitRegex(LAST_NEWLINE_UNICODE));\r\nregister(splitRegex(MANY_NEWLINES));\r\nregister(splitRegex(MANY_NEWLINES_WIN32));\r\nregister(splitRegex(MANY_NEWLINES_UNICODE));","IsDeferred":false},{"Name":"manual","Code":"register(splitManual(NO_NEWLINE));\r\nregister(splitManual(LAST_NEWLINE));\r\nregister(splitManual(LAST_NEWLINE_WIN32));\r\nregister(splitManual(LAST_NEWLINE_UNICODE));\r\nregister(splitManual(MANY_NEWLINES));\r\nregister(splitManual(MANY_NEWLINES_WIN32));\r\nregister(splitManual(MANY_NEWLINES_UNICODE));","IsDeferred":false}]}