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

Side by Side Diff: src/serialize.cc

Issue 239133002: Refactoring: HashMap: provide a pointer match function, so users don't need to. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/serialize.h ('k') | 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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 isolate, 579 isolate,
580 entry, 580 entry,
581 Deoptimizer::LAZY, 581 Deoptimizer::LAZY,
582 Deoptimizer::CALCULATE_ENTRY_ADDRESS); 582 Deoptimizer::CALCULATE_ENTRY_ADDRESS);
583 Add(address, LAZY_DEOPTIMIZATION, entry, "lazy_deopt"); 583 Add(address, LAZY_DEOPTIMIZATION, entry, "lazy_deopt");
584 } 584 }
585 } 585 }
586 586
587 587
588 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) 588 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate)
589 : encodings_(Match), 589 : encodings_(HashMap::PointersMatch),
590 isolate_(isolate) { 590 isolate_(isolate) {
591 ExternalReferenceTable* external_references = 591 ExternalReferenceTable* external_references =
592 ExternalReferenceTable::instance(isolate_); 592 ExternalReferenceTable::instance(isolate_);
593 for (int i = 0; i < external_references->size(); ++i) { 593 for (int i = 0; i < external_references->size(); ++i) {
594 Put(external_references->address(i), i); 594 Put(external_references->address(i), i);
595 } 595 }
596 } 596 }
597 597
598 598
599 uint32_t ExternalReferenceEncoder::Encode(Address key) const { 599 uint32_t ExternalReferenceEncoder::Encode(Address key) const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 address_to_name_map_.Remove(from); 673 address_to_name_map_.Remove(from);
674 } 674 }
675 675
676 const char* Lookup(Address address) { 676 const char* Lookup(Address address) {
677 return address_to_name_map_.Lookup(address); 677 return address_to_name_map_.Lookup(address);
678 } 678 }
679 679
680 private: 680 private:
681 class NameMap { 681 class NameMap {
682 public: 682 public:
683 NameMap() : impl_(&PointerEquals) {} 683 NameMap() : impl_(HashMap::PointersMatch) {}
684 684
685 ~NameMap() { 685 ~NameMap() {
686 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) { 686 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) {
687 DeleteArray(static_cast<const char*>(p->value)); 687 DeleteArray(static_cast<const char*>(p->value));
688 } 688 }
689 } 689 }
690 690
691 void Insert(Address code_address, const char* name, int name_size) { 691 void Insert(Address code_address, const char* name, int name_size) {
692 HashMap::Entry* entry = FindOrCreateEntry(code_address); 692 HashMap::Entry* entry = FindOrCreateEntry(code_address);
693 if (entry->value == NULL) { 693 if (entry->value == NULL) {
(...skipping 19 matching lines...) Expand all
713 HashMap::Entry* from_entry = FindEntry(from); 713 HashMap::Entry* from_entry = FindEntry(from);
714 ASSERT(from_entry != NULL); 714 ASSERT(from_entry != NULL);
715 void* value = from_entry->value; 715 void* value = from_entry->value;
716 RemoveEntry(from_entry); 716 RemoveEntry(from_entry);
717 HashMap::Entry* to_entry = FindOrCreateEntry(to); 717 HashMap::Entry* to_entry = FindOrCreateEntry(to);
718 ASSERT(to_entry->value == NULL); 718 ASSERT(to_entry->value == NULL);
719 to_entry->value = value; 719 to_entry->value = value;
720 } 720 }
721 721
722 private: 722 private:
723 static bool PointerEquals(void* lhs, void* rhs) {
724 return lhs == rhs;
725 }
726
727 static char* CopyName(const char* name, int name_size) { 723 static char* CopyName(const char* name, int name_size) {
728 char* result = NewArray<char>(name_size + 1); 724 char* result = NewArray<char>(name_size + 1);
729 for (int i = 0; i < name_size; ++i) { 725 for (int i = 0; i < name_size; ++i) {
730 char c = name[i]; 726 char c = name[i];
731 if (c == '\0') c = ' '; 727 if (c == '\0') c = ' ';
732 result[i] = c; 728 result[i] = c;
733 } 729 }
734 result[name_size] = '\0'; 730 result[name_size] = '\0';
735 return result; 731 return result;
736 } 732 }
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 1883
1888 bool SnapshotByteSource::AtEOF() { 1884 bool SnapshotByteSource::AtEOF() {
1889 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; 1885 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
1890 for (int x = position_; x < length_; x++) { 1886 for (int x = position_; x < length_; x++) {
1891 if (data_[x] != SerializerDeserializer::nop()) return false; 1887 if (data_[x] != SerializerDeserializer::nop()) return false;
1892 } 1888 }
1893 return true; 1889 return true;
1894 } 1890 }
1895 1891
1896 } } // namespace v8::internal 1892 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698