OLD | NEW |
---|---|
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 6251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6262 return true; | 6262 return true; |
6263 } | 6263 } |
6264 | 6264 |
6265 if (!other.IsBigint() || other.IsNull()) { | 6265 if (!other.IsBigint() || other.IsNull()) { |
6266 return false; | 6266 return false; |
6267 } | 6267 } |
6268 | 6268 |
6269 Bigint& other_bgi = Bigint::Handle(); | 6269 Bigint& other_bgi = Bigint::Handle(); |
6270 other_bgi ^= other.raw(); | 6270 other_bgi ^= other.raw(); |
6271 | 6271 |
6272 return BN_cmp(BNAddr(), other_bgi.BNAddr()) == 0; | 6272 intptr_t len = this->Length(); |
6273 if (len != other_bgi.Length()) { | |
6274 return false; | |
6275 } | |
6276 | |
6277 for (intptr_t i = 0; i < len; i++) { | |
6278 if (this->GetChunkAt(i) != other_bgi.GetChunkAt(i)) { | |
6279 return false; | |
6280 } | |
6281 } | |
6282 return true; | |
6273 } | 6283 } |
6274 | 6284 |
6275 | 6285 |
6276 RawBigint* Bigint::New(const BIGNUM *bn, Heap::Space space) { | |
6277 Isolate* isolate = Isolate::Current(); | |
6278 const Class& cls = Class::Handle(isolate->object_store()->bigint_class()); | |
6279 Bigint& result = Bigint::Handle(); | |
6280 { | |
6281 RawObject* raw = Object::Allocate(cls, | |
6282 Bigint::InstanceSize(bn), | |
6283 space); | |
6284 NoGCScope no_gc; | |
6285 result ^= raw; | |
6286 // Danger Will Robinson! Use of OpenSSL internals! | |
6287 // Copy the OpenSSL BIGNUM to our own heap. Don't fix up our d | |
6288 // pointer, that'll get done for us. | |
6289 BIGNUM* our_bn = result.MutableBNAddr(); | |
6290 // memcpy would be sufficient. | |
6291 memmove(our_bn, bn, sizeof *bn); | |
6292 memmove(result.BNMemory(), bn->d, bn->top * sizeof(BN_ULONG)); | |
6293 // We only allocated/copied the active part. | |
6294 our_bn->dmax = our_bn->top; | |
6295 } | |
6296 | |
6297 return result.raw(); | |
6298 } | |
6299 | |
6300 | |
6301 RawBigint* Bigint::New(const String& str, Heap::Space space) { | 6286 RawBigint* Bigint::New(const String& str, Heap::Space space) { |
6302 return BigintOperations::NewFromCString(str.ToCString(), space); | 6287 return BigintOperations::NewFromCString(str.ToCString(), space); |
6303 } | 6288 } |
6304 | 6289 |
6305 | 6290 |
6306 RawBigint* Bigint::New(int64_t value, Heap::Space space) { | 6291 RawBigint* Bigint::New(int64_t value, Heap::Space space) { |
6307 return BigintOperations::NewFromInt64(value, space); | 6292 return BigintOperations::NewFromInt64(value, space); |
6308 } | 6293 } |
6309 | 6294 |
6310 | 6295 |
(...skipping 19 matching lines...) Expand all Loading... | |
6330 big ^= other.raw(); | 6315 big ^= other.raw(); |
6331 return BigintOperations::Compare(*this, big); | 6316 return BigintOperations::Compare(*this, big); |
6332 } | 6317 } |
6333 if (this->IsNegative() == other.IsNegative()) { | 6318 if (this->IsNegative() == other.IsNegative()) { |
6334 return this->IsNegative() ? -1 : 1; | 6319 return this->IsNegative() ? -1 : 1; |
6335 } | 6320 } |
6336 return this->IsNegative() ? -1 : 1; | 6321 return this->IsNegative() ? -1 : 1; |
6337 } | 6322 } |
6338 | 6323 |
6339 | 6324 |
6325 RawBigint* Bigint::Allocate(intptr_t length, Heap::Space space) { | |
6326 ASSERT(length >= 0); | |
6327 Isolate* isolate = Isolate::Current(); | |
6328 const Class& cls = Class::Handle(isolate->object_store()->bigint_class()); | |
6329 Bigint& result = Bigint::Handle(); | |
6330 { | |
6331 RawObject* raw = Object::Allocate(cls, Bigint::InstanceSize(length), space); | |
6332 NoGCScope no_gc; | |
6333 result ^= raw; | |
6334 result.raw_ptr()->allocated_length_ = length; | |
6335 result.raw_ptr()->signed_length_ = length; | |
6336 } | |
6337 return result.raw(); | |
6338 } | |
6339 | |
6340 | |
6340 static uword ZoneAllocator(intptr_t size) { | 6341 static uword ZoneAllocator(intptr_t size) { |
6341 Zone* zone = Isolate::Current()->current_zone(); | 6342 Zone* zone = Isolate::Current()->current_zone(); |
6342 return zone->Allocate(size); | 6343 return zone->Allocate(size); |
6343 } | 6344 } |
6344 | 6345 |
6345 | 6346 |
6346 const char* Bigint::ToCString() const { | 6347 const char* Bigint::ToCString() const { |
6347 return BigintOperations::ToDecCString(*this, &ZoneAllocator); | 6348 return BigintOperations::ToHexCString(*this, &ZoneAllocator); |
Ivan Posva
2012/02/28 01:38:34
Can you please add a TODO and file a bug to implem
siva
2012/02/28 18:22:18
Done.
| |
6348 } | 6349 } |
6349 | 6350 |
6350 | 6351 |
6351 class StringHasher : ValueObject { | 6352 class StringHasher : ValueObject { |
6352 public: | 6353 public: |
6353 StringHasher() : hash_(0) {} | 6354 StringHasher() : hash_(0) {} |
6354 void Add(int32_t ch) { | 6355 void Add(int32_t ch) { |
6355 hash_ += ch; | 6356 hash_ += ch; |
6356 hash_ += hash_ << 10; | 6357 hash_ += hash_ << 10; |
6357 hash_ ^= hash_ >> 6; | 6358 hash_ ^= hash_ >> 6; |
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8302 result.set_num_args_tested(num_args_tested); | 8303 result.set_num_args_tested(num_args_tested); |
8303 // Number of array elements in one test entry (num_args_tested + 1) | 8304 // Number of array elements in one test entry (num_args_tested + 1) |
8304 intptr_t len = num_args_tested + 1; | 8305 intptr_t len = num_args_tested + 1; |
8305 // IC data array must be null terminated (sentinel entry). | 8306 // IC data array must be null terminated (sentinel entry). |
8306 Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); | 8307 Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); |
8307 result.set_ic_data(ic_data); | 8308 result.set_ic_data(ic_data); |
8308 return result.raw(); | 8309 return result.raw(); |
8309 } | 8310 } |
8310 | 8311 |
8311 } // namespace dart | 8312 } // namespace dart |
OLD | NEW |