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

Unified Diff: runtime/vm/object.h

Issue 14296006: Fast copy between TypedData and ExternalTypedData (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.h
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index a81aaa05a37bbc548f7dadf2e98b2bf88b881ce6..d06c639964de200d79b1793feeefdb6b3d24b061 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -5034,6 +5034,12 @@ class TypedData : public Instance {
return ElementSizeInBytes(cid);
}
+
+ TypeDataElementType ElementType() const {
+ intptr_t cid = raw()->GetClassId();
+ return ElementType(cid);
+ }
+
intptr_t LengthInBytes() const {
intptr_t cid = raw()->GetClassId();
return (ElementSizeInBytes(cid) * Length());
@@ -5086,6 +5092,12 @@ class TypedData : public Instance {
return element_size[class_id - kTypedDataInt8ArrayCid];
siva 2013/04/19 17:38:40 you could use your new ElementType() here instead
kustermann 2013/04/19 19:21:54 Done.
kustermann 2013/04/19 19:21:54 Done.
}
+ static TypeDataElementType ElementType(intptr_t class_id) {
+ ASSERT(RawObject::IsTypedDataClassId(class_id));
+ return static_cast<TypeDataElementType>(
+ class_id - kTypedDataInt8ArrayCid);
+ }
+
static intptr_t MaxElements(intptr_t class_id) {
ASSERT(RawObject::IsTypedDataClassId(class_id));
return (kSmiMax / ElementSizeInBytes(class_id));
@@ -5134,6 +5146,11 @@ class ExternalTypedData : public Instance {
return ElementSizeInBytes(cid);
}
+ TypeDataElementType ElementType() const {
+ intptr_t cid = raw()->GetClassId();
+ return ElementType(cid);
+ }
+
intptr_t LengthInBytes() const {
intptr_t cid = raw()->GetClassId();
return (ElementSizeInBytes(cid) * Length());
@@ -5187,6 +5204,12 @@ class ExternalTypedData : public Instance {
return TypedData::element_size[class_id - kExternalTypedDataInt8ArrayCid];
siva 2013/04/19 17:38:40 Ditto comment about using the new ElementType
kustermann 2013/04/19 19:21:54 Done.
}
+ static TypeDataElementType ElementType(intptr_t class_id) {
+ ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
+ return static_cast<TypeDataElementType>(
+ class_id - kExternalTypedDataInt8ArrayCid);
+ }
+
static intptr_t MaxElements(intptr_t class_id) {
ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
return (kSmiMax / ElementSizeInBytes(class_id));
@@ -5228,6 +5251,28 @@ class ExternalTypedData : public Instance {
};
+template <typename DstType, typename SrcType>
+void TypedArrayCopyData(const DstType& dst, intptr_t dst_offset_in_bytes,
+ const SrcType& src, intptr_t src_offset_in_bytes,
+ intptr_t length_in_bytes) {
+ ASSERT(dst.ElementType() == src.ElementType());
+ ASSERT(Utils::RangeCheck(src_offset_in_bytes,
+ length_in_bytes,
+ src.LengthInBytes()));
+ ASSERT(Utils::RangeCheck(dst_offset_in_bytes,
+ length_in_bytes,
+ dst.LengthInBytes()));
+ {
+ NoGCScope no_gc;
+ if (length_in_bytes > 0) {
+ memmove(dst.DataAddr(dst_offset_in_bytes),
+ src.DataAddr(src_offset_in_bytes),
+ length_in_bytes);
+ }
+ }
+}
siva 2013/04/19 17:38:40 Why not make this the static function of class Typ
kustermann 2013/04/19 19:21:54 Done.
+
+
class TypedDataView : public AllStatic {
public:
static intptr_t ElementSizeInBytes(const Instance& view_obj) {

Powered by Google App Engine
This is Rietveld 408576698