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

Unified Diff: runtime/vm/kernel_binary.h

Issue 2852943003: Move the Kernel string offsets into the VM's heap. (Closed)
Patch Set: Incorporate review comments. Created 3 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
« no previous file with comments | « runtime/vm/kernel.cc ('k') | runtime/vm/kernel_binary.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/kernel_binary.h
diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h
index 66162d7cb33a17131d3f4b4c3935a09b2a7ad7d5..08fe8939501f7319f50c8b709af7eee7d9e6f297 100644
--- a/runtime/vm/kernel_binary.h
+++ b/runtime/vm/kernel_binary.h
@@ -331,7 +331,14 @@ class ReaderHelper {
class Reader {
public:
Reader(const uint8_t* buffer, intptr_t size)
- : buffer_(buffer), size_(size), offset_(0), string_data_offset_(-1) {}
+ : buffer_(buffer),
+ size_(size),
+ offset_(0),
+ string_table_offset_(-1),
+ string_data_offset_(-1),
+ string_offsets_(NULL) {}
+
+ ~Reader() { delete[] string_offsets_; }
uint32_t ReadUInt32() {
ASSERT(offset_ + 4 <= size_);
@@ -504,15 +511,25 @@ class Reader {
const uint8_t* buffer() { return buffer_; }
+ intptr_t string_table_offset() { return string_table_offset_; }
+ void MarkStringTableOffset() {
+ ASSERT(string_table_offset_ == -1);
+ string_table_offset_ = offset_;
+ }
+
intptr_t string_data_offset() { return string_data_offset_; }
void MarkStringDataOffset() {
ASSERT(string_data_offset_ == -1);
string_data_offset_ = offset_;
}
- uint8_t CharacterAt(String* str, intptr_t index) {
- ASSERT(index < str->size());
- return buffer_[string_data_offset_ + str->offset() + index];
+ intptr_t StringLength(intptr_t string_index) {
+ return string_offsets_[string_index + 1] - string_offsets_[string_index];
+ }
+
+ uint8_t CharacterAt(intptr_t string_index, intptr_t index) {
+ ASSERT(index < StringLength(string_index));
+ return buffer_[string_data_offset_ + string_offsets_[string_index] + index];
}
private:
@@ -524,9 +541,17 @@ class Reader {
TokenPosition min_position_;
intptr_t current_script_id_;
+ // When the binary is deserialized the offset of the start of the string table
+ // (the length) and the offset of the start of the string data are recorded.
+ intptr_t string_table_offset_;
intptr_t string_data_offset_;
+ // The string offsets are decoded to support efficient access to string UTF-8
+ // encodings.
+ intptr_t* string_offsets_;
+
friend class PositionScope;
+ friend class Program;
};
« no previous file with comments | « runtime/vm/kernel.cc ('k') | runtime/vm/kernel_binary.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698