Author: [email protected]
Date: Tue Mar 24 06:33:54 2009
New Revision: 1599

Modified:
    branches/bleeding_edge/src/d8.cc
    branches/bleeding_edge/src/d8.h
    branches/bleeding_edge/src/serialize.cc

Log:
Remove stl dependencies from d8.
Review URL: http://codereview.chromium.org/42559

Modified: branches/bleeding_edge/src/d8.cc
==============================================================================
--- branches/bleeding_edge/src/d8.cc    (original)
+++ branches/bleeding_edge/src/d8.cc    Tue Mar 24 06:33:54 2009
@@ -86,7 +86,7 @@
  }


-Shell::CounterMap Shell::counter_map_;
+CounterMap* Shell::counter_map_;
  i::OS::MemoryMappedFile* Shell::counters_file_ = NULL;
  CounterCollection Shell::local_counters_;
  CounterCollection* Shell::counters_ = &local_counters_;
@@ -94,6 +94,13 @@
  Persistent<Context> Shell::evaluation_context_;


+bool CounterMap::Match(void* key1, void* key2) {
+  const char* name1 = reinterpret_cast<const char*>(key1);
+  const char* name2 = reinterpret_cast<const char*>(key2);
+  return strcmp(name1, name2) != 0;
+}
+
+
  // Converts a V8 value to a C string.
  const char* ToCString(const v8::String::Utf8Value& value) {
    return *value ? *value : "<string conversion failed>";
@@ -298,20 +305,31 @@
  }


+int CounterMap::Hash(const char* name) {
+  int h = 0;
+  int c;
+  while ((c = *name++) != 0) {
+    h += h << 5;
+    h += c;
+  }
+  return h;
+}
+
+
  int* Shell::LookupCounter(const char* name) {
-  CounterMap::iterator item = counter_map_.find(name);
-  if (item != counter_map_.end()) {
-    Counter* result = (*item).second;
-    return result->ptr();
+  Counter* counter = counter_map_->Lookup(name);
+  if (counter != NULL) {
+    return counter->ptr();
    }
    Counter* result = counters_->GetNextCounter();
    if (result == NULL) return NULL;
-  counter_map_[name] = result;
+  counter_map_->Set(name, result);
    return result->Bind(name);
  }


  void Shell::Initialize() {
+  Shell::counter_map_ = new CounterMap();
    // Set up counters
    if (i::FLAG_map_counters != NULL)
      MapCounters(i::FLAG_map_counters);
@@ -382,11 +400,9 @@
      ::printf("+----------------------------------------+-------------+\n");
      ::printf("| Name                                   | Value       |\n");
      ::printf("+----------------------------------------+-------------+\n");
-    for (CounterMap::iterator i = counter_map_.begin();
-         i != counter_map_.end();
-         i++) {
-      Counter* counter = (*i).second;
-      ::printf("| %-38s | %11i |\n", (*i).first, counter->value());
+    for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) {
+      Counter* counter = i.CurrentValue();
+      ::printf("| %-38s | %11i |\n", i.CurrentKey(), counter->value());
      }
      ::printf("+----------------------------------------+-------------+\n");
    }

Modified: branches/bleeding_edge/src/d8.h
==============================================================================
--- branches/bleeding_edge/src/d8.h     (original)
+++ branches/bleeding_edge/src/d8.h     Tue Mar 24 06:33:54 2009
@@ -28,12 +28,8 @@
  #ifndef V8_D8_H_
  #define V8_D8_H_

-
-// Disable exceptions on windows to not generate warnings from <map>.
-#define _HAS_EXCEPTIONS 0
-#include <map>
-
  #include "v8.h"
+#include "hashmap.h"


  namespace v8 {
@@ -72,6 +68,43 @@
  };


+class CounterMap {
+ public:
+  CounterMap(): hash_map_(Match) { }
+  Counter* Lookup(const char* name) {
+    i::HashMap::Entry* answer = hash_map_.Lookup(
+        const_cast<char*>(name),
+        Hash(name),
+        false);
+    if (!answer) return NULL;
+    return reinterpret_cast<Counter*>(answer->value);
+  }
+  void Set(const char* name, Counter* value) {
+    i::HashMap::Entry* answer = hash_map_.Lookup(
+        const_cast<char*>(name),
+        Hash(name),
+        true);
+    ASSERT(answer != NULL);
+    answer->value = value;
+  }
+  class Iterator {
+   public:
+    Iterator(CounterMap* map): map_(&map->hash_map_),  
entry_(map_->Start()) { }
+    void Next() { entry_ = map_->Next(entry_); }
+    bool More() { return entry_ != NULL; }
+    const char* CurrentKey() { return static_cast<const  
char*>(entry_->key); }
+    Counter* CurrentValue() { return static_cast<Counter*>(entry_->value);  
}
+   private:
+    i::HashMap* map_;
+    i::HashMap::Entry* entry_;
+  };
+ private:
+  static int Hash(const char* name);
+  static bool Match(void* key1, void* key2);
+  i::HashMap hash_map_;
+};
+
+
  class Shell: public i::AllStatic {
   public:
    static bool ExecuteString(Handle<String> source,
@@ -104,8 +137,7 @@
   private:
    static Persistent<Context> utility_context_;
    static Persistent<Context> evaluation_context_;
-  typedef std::map<const char*, Counter*> CounterMap;
-  static CounterMap counter_map_;
+  static CounterMap* counter_map_;
    // We statically allocate a set of local counters to be used if we
    // don't want to store the stats in a memory-mapped file
    static CounterCollection local_counters_;

Modified: branches/bleeding_edge/src/serialize.cc
==============================================================================
--- branches/bleeding_edge/src/serialize.cc     (original)
+++ branches/bleeding_edge/src/serialize.cc     Tue Mar 24 06:33:54 2009
@@ -963,8 +963,8 @@


  Address Serializer::GetSavedAddress(HeapObject* obj) {
-  HashMap::Entry* entry
-  = saved_addresses_.Lookup(obj, HeapObjectHash(obj), false);
+  HashMap::Entry* entry =
+    saved_addresses_.Lookup(obj, HeapObjectHash(obj), false);
    ASSERT(entry != NULL);
    return reinterpret_cast<Address>(entry->value);
  }

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to