| Index: runtime/vm/object.cc
|
| ===================================================================
|
| --- runtime/vm/object.cc (revision 37119)
|
| +++ runtime/vm/object.cc (working copy)
|
| @@ -7927,6 +7927,16 @@
|
| }
|
|
|
|
|
| +void Script::set_token_pos_to_line_nr(const TypedData& value) const {
|
| + StorePointer(&raw_ptr()->token_pos_to_line_nr_, value.raw());
|
| +}
|
| +
|
| +
|
| +RawTypedData* Script::token_pos_to_line_nr() const {
|
| + return raw_ptr()->token_pos_to_line_nr_;
|
| +}
|
| +
|
| +
|
| void Script::Tokenize(const String& private_key) const {
|
| Isolate* isolate = Isolate::Current();
|
| const TokenStream& tkns = TokenStream::Handle(isolate, tokens());
|
| @@ -7961,8 +7971,13 @@
|
| intptr_t* line,
|
| intptr_t* column) const {
|
| ASSERT(line != NULL);
|
| - const TokenStream& tkns = TokenStream::Handle(tokens());
|
| if (column == NULL) {
|
| + if (token_pos_to_line_nr() != TypedData::null()) {
|
| + const TypedData& array = TypedData::Handle(token_pos_to_line_nr());
|
| + *line = array.GetInt32(token_pos * array.ElementSizeInBytes());
|
| + return;
|
| + }
|
| + const TokenStream& tkns = TokenStream::Handle(tokens());
|
| TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
|
| intptr_t cur_line = line_offset() + 1;
|
| while (tkit.CurrentPosition() < token_pos &&
|
| @@ -7974,6 +7989,7 @@
|
| }
|
| *line = cur_line;
|
| } else {
|
| + const TokenStream& tkns = TokenStream::Handle(tokens());
|
| const String& src = String::Handle(Source());
|
| intptr_t src_pos = tkns.ComputeSourcePosition(token_pos);
|
| Scanner scanner(src, Symbols::Empty());
|
| @@ -7989,6 +8005,32 @@
|
| }
|
|
|
|
|
| +void Script::ComputeTokenPosToLineNumberArray() const {
|
| + if (token_pos_to_line_nr() != TypedData::null()) {
|
| + // Already computed.
|
| + return;
|
| + }
|
| +
|
| + const TokenStream& tkns = TokenStream::Handle(tokens());
|
| + const intptr_t len = ExternalTypedData::Handle(tkns.GetStream()).Length();
|
| + const TypedData& array =
|
| + TypedData::Handle(TypedData::New(kTypedDataInt32ArrayCid, len));
|
| + const intptr_t elem_size_in_bytes = array.ElementSizeInBytes();
|
| + set_token_pos_to_line_nr(array);
|
| + TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
|
| + intptr_t array_offset_in_bytes = 0;
|
| + intptr_t cur_line = line_offset() + 1;
|
| + while (tkit.CurrentTokenKind() != Token::kEOS) {
|
| + array.SetInt32(tkit.CurrentPosition() * elem_size_in_bytes, cur_line);
|
| + array_offset_in_bytes += elem_size_in_bytes;
|
| + if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
|
| + cur_line++;
|
| + }
|
| + tkit.Advance();
|
| + }
|
| +}
|
| +
|
| +
|
| void Script::TokenRangeAtLine(intptr_t line_number,
|
| intptr_t* first_token_index,
|
| intptr_t* last_token_index) const {
|
| @@ -18263,6 +18305,7 @@
|
| if (len < 0 || len > TypedData::MaxElements(class_id)) {
|
| FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len);
|
| }
|
| + ASSERT(RawObject::IsTypedDataClassId(class_id));
|
| TypedData& result = TypedData::Handle();
|
| {
|
| intptr_t lengthInBytes = len * ElementSizeInBytes(class_id);
|
|
|