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

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

Issue 2952193002: VM: Speed up output of UTF8 for 1-byte strings.
Patch Set: Add test that would have caught bug pointed out by Slava Created 3 years, 2 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
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »
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 #ifndef RUNTIME_VM_OBJECT_H_ 5 #ifndef RUNTIME_VM_OBJECT_H_
6 #define RUNTIME_VM_OBJECT_H_ 6 #define RUNTIME_VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 7148 matching lines...) Expand 10 before | Expand all | Expand 10 after
7159 static const RawOneByteString* raw_ptr(const String& str) { 7159 static const RawOneByteString* raw_ptr(const String& str) {
7160 return reinterpret_cast<const RawOneByteString*>(str.raw_ptr()); 7160 return reinterpret_cast<const RawOneByteString*>(str.raw_ptr());
7161 } 7161 }
7162 7162
7163 static uint8_t* CharAddr(const String& str, intptr_t index) { 7163 static uint8_t* CharAddr(const String& str, intptr_t index) {
7164 ASSERT((index >= 0) && (index < str.Length())); 7164 ASSERT((index >= 0) && (index < str.Length()));
7165 ASSERT(str.IsOneByteString()); 7165 ASSERT(str.IsOneByteString());
7166 return &str.UnsafeMutableNonPointer(raw_ptr(str)->data())[index]; 7166 return &str.UnsafeMutableNonPointer(raw_ptr(str)->data())[index];
7167 } 7167 }
7168 7168
7169 static uint8_t* DataStart(const String& str) {
7170 ASSERT(str.IsOneByteString());
7171 return &str.UnsafeMutableNonPointer(raw_ptr(str)->data())[0];
7172 }
7173
7169 static RawOneByteString* ReadFrom(SnapshotReader* reader, 7174 static RawOneByteString* ReadFrom(SnapshotReader* reader,
7170 intptr_t object_id, 7175 intptr_t object_id,
7171 intptr_t tags, 7176 intptr_t tags,
7172 Snapshot::Kind kind, 7177 Snapshot::Kind kind,
7173 bool as_reference); 7178 bool as_reference);
7174 7179
7175 friend class Class; 7180 friend class Class;
7176 friend class String; 7181 friend class String;
7177 friend class Symbols; 7182 friend class Symbols;
7178 friend class ExternalOneByteString; 7183 friend class ExternalOneByteString;
7179 friend class SnapshotReader; 7184 friend class SnapshotReader;
7180 friend class StringHasher; 7185 friend class StringHasher;
7186 friend class Utf8;
7181 }; 7187 };
7182 7188
7183 class TwoByteString : public AllStatic { 7189 class TwoByteString : public AllStatic {
7184 public: 7190 public:
7185 static uint16_t CharAt(const String& str, intptr_t index) { 7191 static uint16_t CharAt(const String& str, intptr_t index) {
7186 ASSERT((index >= 0) && (index < str.Length())); 7192 ASSERT((index >= 0) && (index < str.Length()));
7187 ASSERT(str.IsTwoByteString()); 7193 ASSERT(str.IsTwoByteString());
7188 return raw_ptr(str)->data()[index]; 7194 return raw_ptr(str)->data()[index];
7189 } 7195 }
7190 7196
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
7276 static const RawTwoByteString* raw_ptr(const String& str) { 7282 static const RawTwoByteString* raw_ptr(const String& str) {
7277 return reinterpret_cast<const RawTwoByteString*>(str.raw_ptr()); 7283 return reinterpret_cast<const RawTwoByteString*>(str.raw_ptr());
7278 } 7284 }
7279 7285
7280 static uint16_t* CharAddr(const String& str, intptr_t index) { 7286 static uint16_t* CharAddr(const String& str, intptr_t index) {
7281 ASSERT((index >= 0) && (index < str.Length())); 7287 ASSERT((index >= 0) && (index < str.Length()));
7282 ASSERT(str.IsTwoByteString()); 7288 ASSERT(str.IsTwoByteString());
7283 return &str.UnsafeMutableNonPointer(raw_ptr(str)->data())[index]; 7289 return &str.UnsafeMutableNonPointer(raw_ptr(str)->data())[index];
7284 } 7290 }
7285 7291
7292 static uint16_t* DataStart(const String& str) {
7293 ASSERT(str.IsTwoByteString());
7294 return &str.UnsafeMutableNonPointer(raw_ptr(str)->data())[0];
7295 }
7296
7286 static RawTwoByteString* ReadFrom(SnapshotReader* reader, 7297 static RawTwoByteString* ReadFrom(SnapshotReader* reader,
7287 intptr_t object_id, 7298 intptr_t object_id,
7288 intptr_t tags, 7299 intptr_t tags,
7289 Snapshot::Kind kind, 7300 Snapshot::Kind kind,
7290 bool as_reference); 7301 bool as_reference);
7291 7302
7292 friend class Class; 7303 friend class Class;
7293 friend class String; 7304 friend class String;
7294 friend class SnapshotReader; 7305 friend class SnapshotReader;
7295 friend class Symbols; 7306 friend class Symbols;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7342 static const RawExternalOneByteString* raw_ptr(const String& str) { 7353 static const RawExternalOneByteString* raw_ptr(const String& str) {
7343 return reinterpret_cast<const RawExternalOneByteString*>(str.raw_ptr()); 7354 return reinterpret_cast<const RawExternalOneByteString*>(str.raw_ptr());
7344 } 7355 }
7345 7356
7346 static const uint8_t* CharAddr(const String& str, intptr_t index) { 7357 static const uint8_t* CharAddr(const String& str, intptr_t index) {
7347 ASSERT((index >= 0) && (index < str.Length())); 7358 ASSERT((index >= 0) && (index < str.Length()));
7348 ASSERT(str.IsExternalOneByteString()); 7359 ASSERT(str.IsExternalOneByteString());
7349 return &(raw_ptr(str)->external_data_->data()[index]); 7360 return &(raw_ptr(str)->external_data_->data()[index]);
7350 } 7361 }
7351 7362
7363 static const uint8_t* DataStart(const String& str) {
7364 ASSERT(str.IsExternalOneByteString());
7365 return &(raw_ptr(str)->external_data_->data()[0]);
7366 }
7367
7352 static void SetExternalData(const String& str, 7368 static void SetExternalData(const String& str,
7353 ExternalStringData<uint8_t>* data) { 7369 ExternalStringData<uint8_t>* data) {
7354 ASSERT(str.IsExternalOneByteString()); 7370 ASSERT(str.IsExternalOneByteString());
7355 ASSERT(!Isolate::Current()->heap()->Contains( 7371 ASSERT(!Isolate::Current()->heap()->Contains(
7356 reinterpret_cast<uword>(data->data()))); 7372 reinterpret_cast<uword>(data->data())));
7357 str.StoreNonPointer(&raw_ptr(str)->external_data_, data); 7373 str.StoreNonPointer(&raw_ptr(str)->external_data_, data);
7358 } 7374 }
7359 7375
7360 static void Finalize(void* isolate_callback_data, 7376 static void Finalize(void* isolate_callback_data,
7361 Dart_WeakPersistentHandle handle, 7377 Dart_WeakPersistentHandle handle,
7362 void* peer); 7378 void* peer);
7363 7379
7364 static RawExternalOneByteString* ReadFrom(SnapshotReader* reader, 7380 static RawExternalOneByteString* ReadFrom(SnapshotReader* reader,
7365 intptr_t object_id, 7381 intptr_t object_id,
7366 intptr_t tags, 7382 intptr_t tags,
7367 Snapshot::Kind kind, 7383 Snapshot::Kind kind,
7368 bool as_reference); 7384 bool as_reference);
7369 7385
7370 static intptr_t NextFieldOffset() { 7386 static intptr_t NextFieldOffset() {
7371 // Indicates this class cannot be extended by dart code. 7387 // Indicates this class cannot be extended by dart code.
7372 return -kWordSize; 7388 return -kWordSize;
7373 } 7389 }
7374 7390
7375 friend class Class; 7391 friend class Class;
7376 friend class String; 7392 friend class String;
7377 friend class SnapshotReader; 7393 friend class SnapshotReader;
7378 friend class Symbols; 7394 friend class Symbols;
7395 friend class Utf8;
7379 }; 7396 };
7380 7397
7381 class ExternalTwoByteString : public AllStatic { 7398 class ExternalTwoByteString : public AllStatic {
7382 public: 7399 public:
7383 static uint16_t CharAt(const String& str, intptr_t index) { 7400 static uint16_t CharAt(const String& str, intptr_t index) {
7384 NoSafepointScope no_safepoint; 7401 NoSafepointScope no_safepoint;
7385 return *CharAddr(str, index); 7402 return *CharAddr(str, index);
7386 } 7403 }
7387 7404
7388 static void* GetPeer(const String& str) { 7405 static void* GetPeer(const String& str) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7421 static const RawExternalTwoByteString* raw_ptr(const String& str) { 7438 static const RawExternalTwoByteString* raw_ptr(const String& str) {
7422 return reinterpret_cast<const RawExternalTwoByteString*>(str.raw_ptr()); 7439 return reinterpret_cast<const RawExternalTwoByteString*>(str.raw_ptr());
7423 } 7440 }
7424 7441
7425 static const uint16_t* CharAddr(const String& str, intptr_t index) { 7442 static const uint16_t* CharAddr(const String& str, intptr_t index) {
7426 ASSERT((index >= 0) && (index < str.Length())); 7443 ASSERT((index >= 0) && (index < str.Length()));
7427 ASSERT(str.IsExternalTwoByteString()); 7444 ASSERT(str.IsExternalTwoByteString());
7428 return &(raw_ptr(str)->external_data_->data()[index]); 7445 return &(raw_ptr(str)->external_data_->data()[index]);
7429 } 7446 }
7430 7447
7448 static const uint16_t* DataStart(const String& str) {
7449 ASSERT(str.IsExternalTwoByteString());
7450 return &(raw_ptr(str)->external_data_->data()[0]);
7451 }
7452
7431 static void SetExternalData(const String& str, 7453 static void SetExternalData(const String& str,
7432 ExternalStringData<uint16_t>* data) { 7454 ExternalStringData<uint16_t>* data) {
7433 ASSERT(str.IsExternalTwoByteString()); 7455 ASSERT(str.IsExternalTwoByteString());
7434 ASSERT(!Isolate::Current()->heap()->Contains( 7456 ASSERT(!Isolate::Current()->heap()->Contains(
7435 reinterpret_cast<uword>(data->data()))); 7457 reinterpret_cast<uword>(data->data())));
7436 str.StoreNonPointer(&raw_ptr(str)->external_data_, data); 7458 str.StoreNonPointer(&raw_ptr(str)->external_data_, data);
7437 } 7459 }
7438 7460
7439 static void Finalize(void* isolate_callback_data, 7461 static void Finalize(void* isolate_callback_data,
7440 Dart_WeakPersistentHandle handle, 7462 Dart_WeakPersistentHandle handle,
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
8948 8970
8949 inline void TypeArguments::SetHash(intptr_t value) const { 8971 inline void TypeArguments::SetHash(intptr_t value) const {
8950 // This is only safe because we create a new Smi, which does not cause 8972 // This is only safe because we create a new Smi, which does not cause
8951 // heap allocation. 8973 // heap allocation.
8952 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 8974 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8953 } 8975 }
8954 8976
8955 } // namespace dart 8977 } // namespace dart
8956 8978
8957 #endif // RUNTIME_VM_OBJECT_H_ 8979 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698