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

Side by Side Diff: src/code-stubs.cc

Issue 7497063: Simplify and optimize ToBoolean handling. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 4 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 void ToBooleanStub::PrintName(StringStream* stream) { 333 void ToBooleanStub::PrintName(StringStream* stream) {
334 stream->Add("ToBooleanStub_"); 334 stream->Add("ToBooleanStub_");
335 types_.Print(stream); 335 types_.Print(stream);
336 } 336 }
337 337
338 338
339 void ToBooleanStub::Types::Print(StringStream* stream) const { 339 void ToBooleanStub::Types::Print(StringStream* stream) const {
340 if (IsEmpty()) stream->Add("None"); 340 if (IsEmpty()) stream->Add("None");
341 if (Contains(UNDEFINED)) stream->Add("Undefined"); 341 if (Contains(UNDEFINED)) stream->Add("Undefined");
342 if (Contains(BOOLEAN)) stream->Add("Bool"); 342 if (Contains(BOOLEAN)) stream->Add("Bool");
343 if (Contains(NULL_TYPE)) stream->Add("Null");
343 if (Contains(SMI)) stream->Add("Smi"); 344 if (Contains(SMI)) stream->Add("Smi");
344 if (Contains(NULL_TYPE)) stream->Add("Null");
345 if (Contains(SPEC_OBJECT)) stream->Add("SpecObject"); 345 if (Contains(SPEC_OBJECT)) stream->Add("SpecObject");
346 if (Contains(STRING)) stream->Add("String"); 346 if (Contains(STRING)) stream->Add("String");
347 if (Contains(HEAP_NUMBER)) stream->Add("HeapNumber"); 347 if (Contains(HEAP_NUMBER)) stream->Add("HeapNumber");
348 if (Contains(INTERNAL_OBJECT)) stream->Add("InternalObject");
349 } 348 }
350 349
351 350
352 void ToBooleanStub::Types::TraceTransition(Types to) const { 351 void ToBooleanStub::Types::TraceTransition(Types to) const {
353 if (!FLAG_trace_ic) return; 352 if (!FLAG_trace_ic) return;
354 char buffer[100]; 353 char buffer[100];
355 NoAllocationStringAllocator allocator(buffer, 354 NoAllocationStringAllocator allocator(buffer,
356 static_cast<unsigned>(sizeof(buffer))); 355 static_cast<unsigned>(sizeof(buffer)));
357 StringStream stream(&allocator); 356 StringStream stream(&allocator);
358 stream.Add("[ToBooleanIC ("); 357 stream.Add("[ToBooleanIC (");
(...skipping 19 matching lines...) Expand all
378 Add(SMI); 377 Add(SMI);
379 return Smi::cast(*object)->value() != 0; 378 return Smi::cast(*object)->value() != 0;
380 } else if (object->IsSpecObject()) { 379 } else if (object->IsSpecObject()) {
381 Add(SPEC_OBJECT); 380 Add(SPEC_OBJECT);
382 return !object->IsUndetectableObject(); 381 return !object->IsUndetectableObject();
383 } else if (object->IsString()) { 382 } else if (object->IsString()) {
384 Add(STRING); 383 Add(STRING);
385 return !object->IsUndetectableObject() && 384 return !object->IsUndetectableObject() &&
386 String::cast(*object)->length() != 0; 385 String::cast(*object)->length() != 0;
387 } else if (object->IsHeapNumber()) { 386 } else if (object->IsHeapNumber()) {
387 ASSERT(!object->IsUndetectableObject());
388 Add(HEAP_NUMBER); 388 Add(HEAP_NUMBER);
389 double value = HeapNumber::cast(*object)->value(); 389 double value = HeapNumber::cast(*object)->value();
390 return !object->IsUndetectableObject() && value != 0 && !isnan(value); 390 return value != 0 && !isnan(value);
391 } else { 391 } else {
392 Add(INTERNAL_OBJECT); 392 // We should never see an internal object at runtime here!
393 return !object->IsUndetectableObject(); 393 UNREACHABLE();
394 return true;
394 } 395 }
395 } 396 }
396 397
397 398
398 bool ToBooleanStub::Types::NeedsMap() const { 399 bool ToBooleanStub::Types::NeedsMap() const {
399 return Contains(ToBooleanStub::SPEC_OBJECT) 400 return Contains(ToBooleanStub::SPEC_OBJECT)
400 || Contains(ToBooleanStub::STRING) 401 || Contains(ToBooleanStub::STRING)
401 || Contains(ToBooleanStub::HEAP_NUMBER) 402 || Contains(ToBooleanStub::HEAP_NUMBER);
402 || Contains(ToBooleanStub::INTERNAL_OBJECT); 403 }
404
405
406 bool ToBooleanStub::Types::CanBeUndetectable() const {
407 return Contains(ToBooleanStub::SPEC_OBJECT)
408 || Contains(ToBooleanStub::STRING);
403 } 409 }
404 410
405 411
406 } } // namespace v8::internal 412 } } // namespace v8::internal
OLDNEW
« src/apinatives.js ('K') | « src/code-stubs.h ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698