OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 return %StringReplaceRegExpWithString(subject, | 238 return %StringReplaceRegExpWithString(subject, |
239 search, | 239 search, |
240 TO_STRING_INLINE(replace), | 240 TO_STRING_INLINE(replace), |
241 lastMatchInfo); | 241 lastMatchInfo); |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 // Convert the search argument to a string and search for it. | 245 // Convert the search argument to a string and search for it. |
246 search = TO_STRING_INLINE(search); | 246 search = TO_STRING_INLINE(search); |
247 if (search.length == 1 && | 247 if (search.length == 1 && |
248 subject.length > 0xFF && | |
Yang
2012/01/17 13:07:34
Dealing with short cons string the old way is bett
| |
248 IS_STRING(replace) && | 249 IS_STRING(replace) && |
249 %StringIndexOf(replace, '$', 0) < 0) { | 250 %StringIndexOf(replace, '$', 0) < 0) { |
251 // Searching by traversing a cons string tree and replace with cons of | |
252 // slices works only when the replaced string is a single character, being | |
253 // replaced by a simple string and only pays off for long strings. | |
250 return %StringReplaceOneCharWithString(subject, search, replace); | 254 return %StringReplaceOneCharWithString(subject, search, replace); |
251 } | 255 } |
252 var start = %StringIndexOf(subject, search, 0); | 256 var start = %StringIndexOf(subject, search, 0); |
253 if (start < 0) return subject; | 257 if (start < 0) return subject; |
254 var end = start + search.length; | 258 var end = start + search.length; |
255 | 259 |
256 var builder = new ReplaceResultBuilder(subject); | 260 var builder = new ReplaceResultBuilder(subject); |
257 // prefix | 261 // prefix |
258 builder.addSpecialSlice(0, start); | 262 builder.addSpecialSlice(0, start); |
259 | 263 |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1004 "fixed", StringFixed, | 1008 "fixed", StringFixed, |
1005 "italics", StringItalics, | 1009 "italics", StringItalics, |
1006 "small", StringSmall, | 1010 "small", StringSmall, |
1007 "strike", StringStrike, | 1011 "strike", StringStrike, |
1008 "sub", StringSub, | 1012 "sub", StringSub, |
1009 "sup", StringSup | 1013 "sup", StringSup |
1010 )); | 1014 )); |
1011 } | 1015 } |
1012 | 1016 |
1013 SetUpString(); | 1017 SetUpString(); |
OLD | NEW |