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

Side by Side Diff: src/objects-inl.h

Issue 143303002: Experimental lexer: add handling of sliced strings in SubStringKey (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Fix typo Created 6 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 496 }
497 497
498 virtual MaybeObject* AsObject(Heap* heap); 498 virtual MaybeObject* AsObject(Heap* heap);
499 }; 499 };
500 500
501 501
502 template<class Char> 502 template<class Char>
503 class SubStringKey : public HashTableKey { 503 class SubStringKey : public HashTableKey {
504 public: 504 public:
505 SubStringKey(Handle<String> string, int from, int length) 505 SubStringKey(Handle<String> string, int from, int length)
506 : string_(string), from_(from), length_(length) { } 506 : string_(string), from_(from), length_(length) {
507 if (string_->IsSlicedString()) {
508 string_ = Handle<String>(Unslice(*string_, &from_));
509 }
510 ASSERT(string_->IsSeqString() || string->IsExternalString());
511 }
507 512
508 virtual uint32_t Hash() { 513 virtual uint32_t Hash() {
509 ASSERT(length_ >= 0); 514 ASSERT(length_ >= 0);
510 ASSERT(from_ + length_ <= string_->length()); 515 ASSERT(from_ + length_ <= string_->length());
511 const Char* chars = GetChars() + from_; 516 const Char* chars = GetChars() + from_;
512 hash_field_ = StringHasher::HashSequentialString( 517 hash_field_ = StringHasher::HashSequentialString(
513 chars, length_, string_->GetHeap()->HashSeed()); 518 chars, length_, string_->GetHeap()->HashSeed());
514 uint32_t result = hash_field_ >> String::kHashShift; 519 uint32_t result = hash_field_ >> String::kHashShift;
515 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. 520 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed.
516 return result; 521 return result;
517 } 522 }
518 523
519 virtual uint32_t HashForObject(Object* other) { 524 virtual uint32_t HashForObject(Object* other) {
520 return String::cast(other)->Hash(); 525 return String::cast(other)->Hash();
521 } 526 }
522 527
523 virtual bool IsMatch(Object* string); 528 virtual bool IsMatch(Object* string);
524 virtual MaybeObject* AsObject(Heap* heap); 529 virtual MaybeObject* AsObject(Heap* heap);
525 530
526 private: 531 private:
527 const Char* GetChars(); 532 const Char* GetChars();
533 String* Unslice(String* string, int* offset) {
534 while (string->IsSlicedString()) {
535 SlicedString* sliced = SlicedString::cast(string);
536 *offset += sliced->offset();
537 string = sliced->parent();
538 }
539 return string;
540 }
528 541
529 Handle<String> string_; 542 Handle<String> string_;
530 int from_; 543 int from_;
531 int length_; 544 int length_;
532 uint32_t hash_field_; 545 uint32_t hash_field_;
533 }; 546 };
534 547
535 548
536 class TwoByteStringKey : public SequentialStringKey<uc16> { 549 class TwoByteStringKey : public SequentialStringKey<uc16> {
537 public: 550 public:
(...skipping 6252 matching lines...) Expand 10 before | Expand all | Expand 10 after
6790 #undef READ_UINT32_FIELD 6803 #undef READ_UINT32_FIELD
6791 #undef WRITE_UINT32_FIELD 6804 #undef WRITE_UINT32_FIELD
6792 #undef READ_SHORT_FIELD 6805 #undef READ_SHORT_FIELD
6793 #undef WRITE_SHORT_FIELD 6806 #undef WRITE_SHORT_FIELD
6794 #undef READ_BYTE_FIELD 6807 #undef READ_BYTE_FIELD
6795 #undef WRITE_BYTE_FIELD 6808 #undef WRITE_BYTE_FIELD
6796 6809
6797 } } // namespace v8::internal 6810 } } // namespace v8::internal
6798 6811
6799 #endif // V8_OBJECTS_INL_H_ 6812 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698