Simplify line editor choice in d8.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 28 Feb 2013 17:40:24 +0000 (17:40 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 28 Feb 2013 17:40:24 +0000 (17:40 +0000)
R=rossberg@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/12330171

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13782 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/d8.cc
src/d8.h

index 3ef0d54..2d30a1c 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -123,26 +123,12 @@ class Symbols {
 };
 
 
-LineEditor *LineEditor::first_ = NULL;
+LineEditor *LineEditor::current_ = NULL;
 
 
 LineEditor::LineEditor(Type type, const char* name)
-    : type_(type),
-      name_(name),
-      next_(first_) {
-  first_ = this;
-}
-
-
-LineEditor* LineEditor::Get() {
-  LineEditor* current = first_;
-  LineEditor* best = current;
-  while (current != NULL) {
-    if (current->type_ > best->type_)
-      best = current;
-    current = current->next_;
-  }
-  return best;
+    : type_(type), name_(name) {
+  if (current_ == NULL || current_->type_ < type) current_ = this;
 }
 
 
index 1c3ce0a..f3b3fa1 100644 (file)
--- a/src/d8.h
+++ b/src/d8.h
@@ -128,12 +128,11 @@ class LineEditor {
   virtual void AddHistory(const char* str) { }
 
   const char* name() { return name_; }
-  static LineEditor* Get();
+  static LineEditor* Get() { return current_; }
  private:
   Type type_;
   const char* name_;
-  LineEditor* next_;
-  static LineEditor* first_;
+  static LineEditor* current_;
 };