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

Side by Side Diff: vm/object.cc

Issue 10703150: Don't create a Bigint object first for every integer while parsing the sources, instead first check… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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 | « no previous file | vm/os.h » ('j') | vm/os_linux.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 7664 matching lines...) Expand 10 before | Expand all | Expand 10 after
7675 7675
7676 7676
7677 const char* Integer::ToCString() const { 7677 const char* Integer::ToCString() const {
7678 // Integer is an interface. No instances of Integer should exist. 7678 // Integer is an interface. No instances of Integer should exist.
7679 UNREACHABLE(); 7679 UNREACHABLE();
7680 return "Integer"; 7680 return "Integer";
7681 } 7681 }
7682 7682
7683 7683
7684 RawInteger* Integer::New(const String& str, Heap::Space space) { 7684 RawInteger* Integer::New(const String& str, Heap::Space space) {
7685 // TODO(iposva): If returning a big integer it will not necessarily be in the 7685 // We are not supposed to have integers represented as two byte or
7686 // requested space. 7686 // four byte strings.
7687 const Bigint& big = Bigint::Handle(Bigint::New(str)); 7687 ASSERT(str.IsOneByteString());
7688 if (BigintOperations::FitsIntoSmi(big)) { 7688 const OneByteString& onestr = OneByteString::Cast(str);
7689 return BigintOperations::ToSmi(big); 7689 int64_t value;
7690 } else if (BigintOperations::FitsIntoMint(big)) { 7690 if (!OS::StringToInteger(onestr.ToCString(), &value)) {
7691 return Mint::New(BigintOperations::ToMint(big), space); 7691 const Bigint& big = Bigint::Handle(Bigint::New(onestr, space));
7692 } else { 7692 ASSERT(!BigintOperations::FitsIntoSmi(big));
7693 ASSERT(!BigintOperations::FitsIntoMint(big));
7693 return big.raw(); 7694 return big.raw();
7694 } 7695 }
7696 return Integer::New(value, space);
7695 } 7697 }
7696 7698
7697 7699
7698 RawInteger* Integer::New(int64_t value, Heap::Space space) { 7700 RawInteger* Integer::New(int64_t value, Heap::Space space) {
7699 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 7701 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
7700 return Smi::New(value); 7702 return Smi::New(value);
7701 } 7703 }
7702 return Mint::New(value, space); 7704 return Mint::New(value, space);
7703 } 7705 }
7704 7706
(...skipping 2950 matching lines...) Expand 10 before | Expand all | Expand 10 after
10655 const String& str = String::Handle(pattern()); 10657 const String& str = String::Handle(pattern());
10656 const char* format = "JSRegExp: pattern=%s flags=%s"; 10658 const char* format = "JSRegExp: pattern=%s flags=%s";
10657 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10659 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10658 char* chars = reinterpret_cast<char*>( 10660 char* chars = reinterpret_cast<char*>(
10659 Isolate::Current()->current_zone()->Allocate(len + 1)); 10661 Isolate::Current()->current_zone()->Allocate(len + 1));
10660 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10662 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10661 return chars; 10663 return chars;
10662 } 10664 }
10663 10665
10664 } // namespace dart 10666 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/os.h » ('j') | vm/os_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698