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

Side by Side Diff: test/mjsunit/string-indexof-1.js

Issue 1324453007: Reland: Speedup stringsearch for two byte strings (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix out-of-bounds access Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « src/string-search.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 assertEquals(1, twoByteString.indexOf("\u0391\u03a3"), "Alpha Sigma"); 70 assertEquals(1, twoByteString.indexOf("\u0391\u03a3"), "Alpha Sigma");
71 assertEquals(2, twoByteString.indexOf("\u03a3\u03a3"), "Sigma Sigma"); 71 assertEquals(2, twoByteString.indexOf("\u03a3\u03a3"), "Sigma Sigma");
72 assertEquals(3, twoByteString.indexOf("\u03a3\u0395"), "Sigma Epsilon"); 72 assertEquals(3, twoByteString.indexOf("\u03a3\u0395"), "Sigma Epsilon");
73 73
74 assertEquals(-1, twoByteString.indexOf("\u0391\u03a3\u0395"), 74 assertEquals(-1, twoByteString.indexOf("\u0391\u03a3\u0395"),
75 "Not Alpha Sigma Epsilon"); 75 "Not Alpha Sigma Epsilon");
76 76
77 //single char pattern 77 //single char pattern
78 assertEquals(4, twoByteString.indexOf("\u0395")); 78 assertEquals(4, twoByteString.indexOf("\u0395"));
79 79
80 // test string with alignment traps
81 var alignmentString = "\u1122\u2211\u2222\uFF00\u00FF\u00FF";
82 assertEquals(2, alignmentString.indexOf("\u2222"));
83 assertEquals(4, alignmentString.indexOf("\u00FF\u00FF"));
84
85 var longAlignmentString = "\uFF00" + "\u00FF".repeat(10);
86 assertEquals(1,
87 longAlignmentString.indexOf("\u00FF".repeat(10)));
88
89 // test string with first character match at the end
90 var boundsString = "112233";
91 assertEquals(-1, boundsString.indexOf("334455"));
92 assertEquals(-1, boundsString.indexOf("334455".repeat(10)));
93
80 // Test complex string indexOf algorithms. Only trigger for long strings. 94 // Test complex string indexOf algorithms. Only trigger for long strings.
81 95
82 // Long string that isn't a simple repeat of a shorter string. 96 // Long string that isn't a simple repeat of a shorter string.
83 var long = "A"; 97 var long = "A";
84 for(var i = 66; i < 76; i++) { // from 'B' to 'K' 98 for(var i = 66; i < 76; i++) { // from 'B' to 'K'
85 long = long + String.fromCharCode(i) + long; 99 long = long + String.fromCharCode(i) + long;
86 } 100 }
87 101
88 // pattern of 15 chars, repeated every 16 chars in long 102 // pattern of 15 chars, repeated every 16 chars in long
89 var pattern = "ABACABADABACABA"; 103 var pattern = "ABACABADABACABA";
(...skipping 26 matching lines...) Expand all
116 var lengths = [1, 4, 15]; // Single char, simple and complex. 130 var lengths = [1, 4, 15]; // Single char, simple and complex.
117 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; 131 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
118 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { 132 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
119 var length = lengths[lengthIndex]; 133 var length = lengths[lengthIndex];
120 for (var i = 0; i < indices.length; i++) { 134 for (var i = 0; i < indices.length; i++) {
121 var index = indices[i]; 135 var index = indices[i];
122 var pattern = allCharsString.substring(index, index + length); 136 var pattern = allCharsString.substring(index, index + length);
123 assertEquals(index, allCharsString.indexOf(pattern)); 137 assertEquals(index, allCharsString.indexOf(pattern));
124 } 138 }
125 } 139 }
OLDNEW
« no previous file with comments | « src/string-search.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698