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

Side by Side Diff: src/factory.cc

Issue 239243018: Heap::AllocateStringFromOneByte() and major part of its callers handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing comment + some cleanup Created 6 years, 8 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
« no previous file with comments | « src/factory.h ('k') | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "factory.h" 5 #include "factory.h"
6 6
7 #include "macro-assembler.h" 7 #include "macro-assembler.h"
8 #include "isolate-inl.h" 8 #include "isolate-inl.h"
9 #include "v8conversions.h" 9 #include "v8conversions.h"
10 10
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 String); 264 String);
265 } 265 }
266 266
267 267
268 template Handle<String> Factory::InternalizeStringWithKey< 268 template Handle<String> Factory::InternalizeStringWithKey<
269 SubStringKey<uint8_t> > (SubStringKey<uint8_t>* key); 269 SubStringKey<uint8_t> > (SubStringKey<uint8_t>* key);
270 template Handle<String> Factory::InternalizeStringWithKey< 270 template Handle<String> Factory::InternalizeStringWithKey<
271 SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key); 271 SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key);
272 272
273 273
274 Handle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string, 274 MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
275 PretenureFlag pretenure) { 275 PretenureFlag pretenure) {
276 CALL_HEAP_FUNCTION( 276 int length = string.length();
277 if (length == 1) {
278 return LookupSingleCharacterStringFromCode(string[0]);
279 }
280 Handle<SeqOneByteString> result;
281 ASSIGN_RETURN_ON_EXCEPTION(
277 isolate(), 282 isolate(),
278 isolate()->heap()->AllocateStringFromOneByte(string, pretenure), 283 result,
284 NewRawOneByteString(string.length(), pretenure),
279 String); 285 String);
286
287 DisallowHeapAllocation no_gc;
288 // Copy the characters into the new object.
289 CopyChars(SeqOneByteString::cast(*result)->GetChars(),
290 string.start(),
291 length);
292 return result;
280 } 293 }
281 294
282 Handle<String> Factory::NewStringFromUtf8(Vector<const char> string, 295 MaybeHandle<String> Factory::NewStringFromUtf8(Vector<const char> string,
283 PretenureFlag pretenure) { 296 PretenureFlag pretenure) {
284 // Check for ASCII first since this is the common case. 297 // Check for ASCII first since this is the common case.
285 const char* start = string.start(); 298 const char* start = string.start();
286 int length = string.length(); 299 int length = string.length();
287 int non_ascii_start = String::NonAsciiStart(start, length); 300 int non_ascii_start = String::NonAsciiStart(start, length);
288 if (non_ascii_start >= length) { 301 if (non_ascii_start >= length) {
289 // If the string is ASCII, we do not need to convert the characters 302 // If the string is ASCII, we do not need to convert the characters
290 // since UTF8 is backwards compatible with ASCII. 303 // since UTF8 is backwards compatible with ASCII.
291 return NewStringFromOneByte(Vector<const uint8_t>::cast(string), pretenure); 304 return NewStringFromOneByte(Vector<const uint8_t>::cast(string), pretenure);
292 } 305 }
293 // Non-ASCII and we need to decode. 306 // Non-ASCII and we need to decode.
294 CALL_HEAP_FUNCTION( 307 CALL_HEAP_FUNCTION(
295 isolate(), 308 isolate(),
296 isolate()->heap()->AllocateStringFromUtf8Slow(string, 309 isolate()->heap()->AllocateStringFromUtf8Slow(string,
297 non_ascii_start, 310 non_ascii_start,
298 pretenure), 311 pretenure),
299 String); 312 String);
300 } 313 }
301 314
302 315
303 Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string, 316 MaybeHandle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
304 PretenureFlag pretenure) { 317 PretenureFlag pretenure) {
305 CALL_HEAP_FUNCTION( 318 CALL_HEAP_FUNCTION(
306 isolate(), 319 isolate(),
307 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), 320 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
308 String); 321 String);
309 } 322 }
310 323
311 324
312 MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString( 325 MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString(
313 int length, PretenureFlag pretenure) { 326 int length, PretenureFlag pretenure) {
314 CALL_HEAP_FUNCTION( 327 CALL_HEAP_FUNCTION(
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 space -= Min(space, strlen(arg.get())); 1204 space -= Min(space, strlen(arg.get()));
1192 p = &buffer[kBufferSize] - space; 1205 p = &buffer[kBufferSize] - space;
1193 } 1206 }
1194 } 1207 }
1195 } 1208 }
1196 if (space > 0) { 1209 if (space > 0) {
1197 *p = '\0'; 1210 *p = '\0';
1198 } else { 1211 } else {
1199 buffer[kBufferSize - 1] = '\0'; 1212 buffer[kBufferSize - 1] = '\0';
1200 } 1213 }
1201 Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); 1214 return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked();
1202 return error_string;
1203 } 1215 }
1204 1216
1205 1217
1206 Handle<Object> Factory::NewError(const char* maker, 1218 Handle<Object> Factory::NewError(const char* maker,
1207 const char* message, 1219 const char* message,
1208 Handle<JSArray> args) { 1220 Handle<JSArray> args) {
1209 Handle<String> make_str = InternalizeUtf8String(maker); 1221 Handle<String> make_str = InternalizeUtf8String(maker);
1210 Handle<Object> fun_obj = Object::GetProperty( 1222 Handle<Object> fun_obj = Object::GetProperty(
1211 isolate()->js_builtins_object(), make_str).ToHandleChecked(); 1223 isolate()->js_builtins_object(), make_str).ToHandleChecked();
1212 // If the builtins haven't been properly configured yet this error 1224 // If the builtins haven't been properly configured yet this error
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 if (number->IsSmi()) { 1961 if (number->IsSmi()) {
1950 int num = Handle<Smi>::cast(number)->value(); 1962 int num = Handle<Smi>::cast(number)->value();
1951 str = IntToCString(num, buffer); 1963 str = IntToCString(num, buffer);
1952 } else { 1964 } else {
1953 double num = Handle<HeapNumber>::cast(number)->value(); 1965 double num = Handle<HeapNumber>::cast(number)->value();
1954 str = DoubleToCString(num, buffer); 1966 str = DoubleToCString(num, buffer);
1955 } 1967 }
1956 1968
1957 // We tenure the allocated string since it is referenced from the 1969 // We tenure the allocated string since it is referenced from the
1958 // number-string cache which lives in the old space. 1970 // number-string cache which lives in the old space.
1959 Handle<String> js_string = NewStringFromOneByte(OneByteVector(str), TENURED); 1971 Handle<String> js_string = NewStringFromAsciiChecked(str, TENURED);
1960 SetNumberStringCache(number, js_string); 1972 SetNumberStringCache(number, js_string);
1961 return js_string; 1973 return js_string;
1962 } 1974 }
1963 1975
1964 1976
1965 Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut( 1977 Handle<SeededNumberDictionary> Factory::DictionaryAtNumberPut(
1966 Handle<SeededNumberDictionary> dictionary, 1978 Handle<SeededNumberDictionary> dictionary,
1967 uint32_t key, 1979 uint32_t key,
1968 Handle<Object> value) { 1980 Handle<Object> value) {
1969 CALL_HEAP_FUNCTION(isolate(), 1981 CALL_HEAP_FUNCTION(isolate(),
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 if (String::Equals(name, infinity_string())) return infinity_value(); 2343 if (String::Equals(name, infinity_string())) return infinity_value();
2332 return Handle<Object>::null(); 2344 return Handle<Object>::null();
2333 } 2345 }
2334 2346
2335 2347
2336 Handle<Object> Factory::ToBoolean(bool value) { 2348 Handle<Object> Factory::ToBoolean(bool value) {
2337 return value ? true_value() : false_value(); 2349 return value ? true_value() : false_value();
2338 } 2350 }
2339 2351
2340 } } // namespace v8::internal 2352 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698