Commit 944258f9 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Remove stl dependencies from d8.

Review URL: http://codereview.chromium.org/42559

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1599 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 89a43b8f
......@@ -86,7 +86,7 @@ i::SmartPointer<char> DumbLineEditor::Prompt(const char* prompt) {
}
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::utility_context_;
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 @@ void Shell::MapCounters(const char* name) {
}
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 @@ void Shell::OnExit() {
::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");
}
......
......@@ -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 CounterCollection {
};
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 @@ class Shell: public i::AllStatic {
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_;
......
......@@ -963,8 +963,8 @@ bool Serializer::IsVisited(HeapObject* obj) {
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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment