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

Side by Side Diff: test/mjsunit/string-slices.js

Issue 7744052: Generated code for substring slices in ia32. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Another set of small changes. Created 9 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 | Annotate | Revision Log
« src/ia32/code-stubs-ia32.cc ('K') | « src/x64/lithium-codegen-x64.cc ('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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 66
67 // Test substrings of different lengths and alignments. 67 // Test substrings of different lengths and alignments.
68 // First ASCII. 68 // First ASCII.
69 var x = "ASCII"; 69 var x = "ASCII";
70 for (var i = 0; i < 25; i++) { 70 for (var i = 0; i < 25; i++) {
71 x += (i >> 4).toString(16) + (i & 0x0f).toString(16); 71 x += (i >> 4).toString(16) + (i & 0x0f).toString(16);
72 } 72 }
73 /x/.exec(x); // Try to force a flatten. 73 /x/.exec(x); // Try to force a flatten.
74 for (var i = 5; i < 25; i++) { 74 for (var i = 5; i < 25; i++) {
75 for (var j = 12; j < 25; j++) { 75 for (var j = 0; j < 25; j++) {
76 var z = x.substring(i, i+j); 76 var z = x.substring(i, i+j);
77 var w = Math.random() * 42; // Allocate something new in new-space. 77 var w = Math.random() * 42; // Allocate something new in new-space.
78 assertEquals(j, z.length); 78 assertEquals(j, z.length);
79 for (var k = 0; k < j; k++) { 79 for (var k = 0; k < j; k++) {
80 assertEquals(x.charAt(i+k), z.charAt(k)); 80 assertEquals(x.charAt(i+k), z.charAt(k));
81 } 81 }
82 } 82 }
83 } 83 }
84 // Then two-byte strings. 84 // Then two-byte strings.
85 x = "UC16\u2028"; // Non-ascii char forces two-byte string. 85 x = "UC16\u2028"; // Non-ascii char forces two-byte string.
(...skipping 17 matching lines...) Expand all
103 x += x; // 2^5 103 x += x; // 2^5
104 x += x; 104 x += x;
105 x += x; 105 x += x;
106 x += x; 106 x += x;
107 x += x; 107 x += x;
108 x += x; // 2^10 108 x += x; // 2^10
109 x += x; 109 x += x;
110 x += x; 110 x += x;
111 var xl = x.length; 111 var xl = x.length;
112 var cache = []; 112 var cache = [];
113 for (var i = 0; i < 10000; i++) { 113 for (var i = 0; i < 1000; i++) {
114 var z = x.substring(i % xl); 114 var z = x.substring(i % xl);
115 assertEquals(xl - (i % xl), z.length); 115 assertEquals(xl - (i % xl), z.length);
116 cache.push(z); 116 cache.push(z);
117 } 117 }
118 118
119 119
120 // Same with two-byte strings 120 // Same with two-byte strings
121 var x = "\u2028123456789ABCDEF"; 121 var x = "\u2028123456789ABCDEF";
122 x += x; // 2^5 122 x += x; // 2^5
123 x += x; 123 x += x;
124 x += x; 124 x += x;
125 x += x; 125 x += x;
126 x += x; 126 x += x;
127 x += x; // 2^10 127 x += x; // 2^10
128 x += x; 128 x += x;
129 x += x; 129 x += x;
130 var xl = x.length; 130 var xl = x.length;
131 var cache = []; 131 var cache = [];
132 for (var i = 0; i < 10000; i++) { 132 for (var i = 0; i < 1000; i++) {
133 var z = x.substring(i % xl); 133 var z = x.substring(i % xl);
134 assertEquals(xl - (i % xl), z.length); 134 assertEquals(xl - (i % xl), z.length);
135 cache.push(z); 135 cache.push(z);
136 } 136 }
137 137
138 // Substring of substring. 138 // Substring of substring.
139 var cache = []; 139 var cache = [];
140 var last = x; 140 var last = x;
141 var offset = 0; 141 var offset = 0;
142 for (var i = 0; i < 64; i++) { 142 for (var i = 0; i < 64; i++) {
143 var z = last.substring(i); 143 var z = last.substring(i);
144 last = z; 144 last = z;
145 cache.push(z); 145 cache.push(z);
146 offset += i; 146 offset += i;
147 } 147 }
148 for (var i = 63; i >= 0; i--) { 148 for (var i = 63; i >= 0; i--) {
149 var z = cache.pop(); 149 var z = cache.pop();
150 assertTrue(/\u2028123456789ABCDEF/.test(z)); 150 assertTrue(/\u2028123456789ABCDEF/.test(z));
151 assertEquals(xl - offset, z.length); 151 assertEquals(xl - offset, z.length);
152 assertEquals(x.charAt(i*(i+1)/2), z.charAt(0));
152 offset -= i; 153 offset -= i;
153 } 154 }
154 155
155 // Test charAt for different strings. 156 // Test charAt for different strings.
156 function f(s1, s2, s3, i) { 157 function f(s1, s2, s3, i) {
157 assertEquals(String.fromCharCode(97+i%11), s1.charAt(i%11)); 158 assertEquals(String.fromCharCode(97+i%11), s1.charAt(i%11));
158 assertEquals(String.fromCharCode(97+i%11), s2.charAt(i%11)); 159 assertEquals(String.fromCharCode(97+i%11), s2.charAt(i%11));
159 assertEquals(String.fromCharCode(98+i%11), s3.charAt(i%11)); 160 assertEquals(String.fromCharCode(98+i%11), s3.charAt(i%11));
160 assertEquals(String.fromCharCode(101), s3.charAt(3)); 161 assertEquals(String.fromCharCode(101), s3.charAt(3));
161 } 162 }
(...skipping 27 matching lines...) Expand all
189 utf.substring(5,1) + utf.substring(3,7)); 190 utf.substring(5,1) + utf.substring(3,7));
190 191
191 /* 192 /*
192 // Externalizing strings. 193 // Externalizing strings.
193 var a = "123456789qwertyuiopasdfghjklzxcvbnm"; 194 var a = "123456789qwertyuiopasdfghjklzxcvbnm";
194 var b = a.slice(1,-1); 195 var b = a.slice(1,-1);
195 assertEquals(a.slice(1,-1), b); 196 assertEquals(a.slice(1,-1), b);
196 externalizeString(a); 197 externalizeString(a);
197 assertEquals(a.slice(1,-1), b); 198 assertEquals(a.slice(1,-1), b);
198 */ 199 */
OLDNEW
« src/ia32/code-stubs-ia32.cc ('K') | « src/x64/lithium-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698