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

Side by Side Diff: runtime/vm/object.cc

Issue 9235067: Use ByteArray's native for Socket and File. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 (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 7488 matching lines...) Expand 10 before | Expand all | Expand 10 after
7499 } 7499 }
7500 7500
7501 7501
7502 intptr_t ByteArray::Length() const { 7502 intptr_t ByteArray::Length() const {
7503 // ByteArray is an abstract class. 7503 // ByteArray is an abstract class.
7504 UNREACHABLE(); 7504 UNREACHABLE();
7505 return 0; 7505 return 0;
7506 } 7506 }
7507 7507
7508 7508
7509 void ByteArray::Copy(uint8_t* dst,
7510 const ByteArray& src,
7511 intptr_t src_offset,
7512 intptr_t length) {
7513 ASSERT(Utils::RangeCheck(src_offset, length, src.Length()));
7514 {
7515 NoGCScope no_gc;
7516 memmove(dst, src.ByteAddr(src_offset), length);
7517 }
7518 }
7519
7520
7521 void ByteArray::Copy(const ByteArray& dst,
7522 intptr_t dst_offset,
7523 const uint8_t* src,
7524 intptr_t length) {
7525 ASSERT(Utils::RangeCheck(dst_offset, length, dst.Length()));
7526 {
7527 NoGCScope no_gc;
7528 memmove(dst.ByteAddr(dst_offset), src, length);
7529 }
7530 }
7531
7532
7533 void ByteArray::Copy(const ByteArray& dst,
7534 intptr_t dst_offset,
7535 const ByteArray& src,
7536 intptr_t src_offset,
7537 intptr_t length) {
7538 ASSERT(Utils::RangeCheck(src_offset, length, src.Length()));
7539 ASSERT(Utils::RangeCheck(dst_offset, length, dst.Length()));
7540 {
7541 NoGCScope no_gc;
7542 memmove(dst.ByteAddr(dst_offset), src.ByteAddr(src_offset), length);
7543 }
7544 }
7545
7546
7547 uint8_t* ByteArray::ByteAddr(intptr_t byte_offset) const {
7548 // ByteArray is an abstract class.
7549 UNREACHABLE();
7550 return NULL;
7551 }
7552
7553
7509 const char* ByteArray::ToCString() const { 7554 const char* ByteArray::ToCString() const {
7510 // ByteArray is an abstract class. 7555 // ByteArray is an abstract class.
7511 UNREACHABLE(); 7556 UNREACHABLE();
7512 return "ByteArray"; 7557 return "ByteArray";
7513 } 7558 }
7514 7559
7515 7560
7516 RawInternalByteArray* InternalByteArray::New(intptr_t len, 7561 RawInternalByteArray* InternalByteArray::New(intptr_t len,
7517 Heap::Space space) { 7562 Heap::Space space) {
7518 Isolate* isolate = Isolate::Current(); 7563 Isolate* isolate = Isolate::Current();
7519 const Class& internal_byte_array_class = 7564 const Class& internal_byte_array_class =
7520 Class::Handle(isolate->object_store()->internal_byte_array_class()); 7565 Class::Handle(isolate->object_store()->internal_byte_array_class());
7521 InternalByteArray& result = InternalByteArray::Handle(); 7566 InternalByteArray& result = InternalByteArray::Handle();
7522 { 7567 {
7523 RawObject* raw = Object::Allocate(internal_byte_array_class, 7568 RawObject* raw = Object::Allocate(internal_byte_array_class,
7524 InternalByteArray::InstanceSize(len), 7569 InternalByteArray::InstanceSize(len),
7525 space); 7570 space);
7526 NoGCScope no_gc; 7571 NoGCScope no_gc;
7527 result ^= raw; 7572 result ^= raw;
7528 result.SetLength(len); 7573 result.SetLength(len);
7529 memset(result.Addr<uint8_t>(0), 0, len); 7574 if (len > 0) {
7575 memset(result.Addr<uint8_t>(0), 0, len);
7576 }
7530 } 7577 }
7531 return result.raw(); 7578 return result.raw();
7532 } 7579 }
7533 7580
7534 7581
7535 RawInternalByteArray* InternalByteArray::New(const uint8_t* data, 7582 RawInternalByteArray* InternalByteArray::New(const uint8_t* data,
7536 intptr_t len, 7583 intptr_t len,
7537 Heap::Space space) { 7584 Heap::Space space) {
7538 InternalByteArray& result = 7585 InternalByteArray& result =
7539 InternalByteArray::Handle(InternalByteArray::New(len, space)); 7586 InternalByteArray::Handle(InternalByteArray::New(len, space));
7540 { 7587 {
7541 NoGCScope no_gc; 7588 NoGCScope no_gc;
7542 memmove(result.Addr<uint8_t>(0), data, len); 7589 if (len > 0) {
7590 memmove(result.Addr<uint8_t>(0), data, len);
7591 }
7543 } 7592 }
7544 return result.raw(); 7593 return result.raw();
7545 } 7594 }
7546 7595
7547 7596
7548 const char* InternalByteArray::ToCString() const { 7597 const char* InternalByteArray::ToCString() const {
7549 return "_InternalByteArray"; 7598 return "_InternalByteArray";
7550 } 7599 }
7551 7600
7552 7601
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
7877 const String& str = String::Handle(pattern()); 7926 const String& str = String::Handle(pattern());
7878 const char* format = "JSRegExp: pattern=%s flags=%s"; 7927 const char* format = "JSRegExp: pattern=%s flags=%s";
7879 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 7928 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
7880 char* chars = reinterpret_cast<char*>( 7929 char* chars = reinterpret_cast<char*>(
7881 Isolate::Current()->current_zone()->Allocate(len + 1)); 7930 Isolate::Current()->current_zone()->Allocate(len + 1));
7882 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 7931 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
7883 return chars; 7932 return chars;
7884 } 7933 }
7885 7934
7886 } // namespace dart 7935 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698