Remove all instances of std::vector.
authorDavid Anderson <dvander@alliedmods.net>
Sat Jul 07 21:08:47 2012 -0700 (2012-07-07)
changeset 584d6265f95ff1
parent 57 8f1e74d35718
child 59 b7d61ddb3c8d
Remove all instances of std::vector.
jitcraft/BytecodeCompiler.cpp
jitcraft/BytecodeEmitter.cpp
jitcraft/BytecodeEmitter.h
jitcraft/Parser.h
jitcraft/Scopes.cpp
jitcraft/Scopes.h
jitcraft/Vector.h
     1.1 --- a/jitcraft/BytecodeCompiler.cpp	Sat Jul 07 21:01:39 2012 -0700
     1.2 +++ b/jitcraft/BytecodeCompiler.cpp	Sat Jul 07 21:08:47 2012 -0700
     1.3 @@ -700,11 +700,11 @@
     1.4      for (size_t i = 0; i < node->scope()->maxContainedLocals(); i++)
     1.5          assert(locals_->at(i));
     1.6  
     1.7 -    Local<FixedArray> objects(zone_, FixedArray::New(zone_, __ objects()->size(), Heap::Tenure_Old));
     1.8 +    Local<FixedArray> objects(zone_, FixedArray::New(zone_, __ objects()->length(), Heap::Tenure_Old));
     1.9      if (!objects)
    1.10          return NULL;
    1.11  
    1.12 -    for (size_t i = 0; i < __ objects()->size(); i++)
    1.13 +    for (size_t i = 0; i < __ objects()->length(); i++)
    1.14          objects->set(zone_, i, *(__ objects()->at(i)));
    1.15  
    1.16      Local<ByteArray> safepoints(zone_);
    1.17 @@ -713,15 +713,15 @@
    1.18      // bytecode, record them now. We do this by building a list of tuples;
    1.19      // each tuple contains the pc offset, and a bitset containing which stack
    1.20      // slots must be scanned by the gc.
    1.21 -    if (__ oopRecords()->size()) {
    1.22 +    if (__ oopRecords()->length()) {
    1.23          size_t bytesPerSafepoint = Code::BytesPerSafepoint(__ maxStackDepth());
    1.24 -        size_t gcmapSize = bytesPerSafepoint * __ oopRecords()->size();
    1.25 +        size_t gcmapSize = bytesPerSafepoint * __ oopRecords()->length();
    1.26          safepoints = ByteArray::New(zone_, gcmapSize, Heap::Tenure_Old);
    1.27          if (!safepoints)
    1.28              return NULL;
    1.29  
    1.30          Address cursor = safepoints->raw();
    1.31 -        for (size_t i = 0; i < __ oopRecords()->size(); i++) {
    1.32 +        for (size_t i = 0; i < __ oopRecords()->length(); i++) {
    1.33              OopRecord *record = __ oopRecords()->at(i);
    1.34              assert(record->depth <= __ maxStackDepth());
    1.35  
     2.1 --- a/jitcraft/BytecodeEmitter.cpp	Sat Jul 07 21:01:39 2012 -0700
     2.2 +++ b/jitcraft/BytecodeEmitter.cpp	Sat Jul 07 21:08:47 2012 -0700
     2.3 @@ -71,7 +71,7 @@
     2.4  void
     2.5  BytecodeEmitter::recordOops()
     2.6  {
     2.7 -    OopRecord *record = new (pool_) OopRecord(oopMap_.size(), position());
     2.8 +    OopRecord *record = new (pool_) OopRecord(oopMap_.length(), position());
     2.9  
    2.10      record->slots = (bool *)pool_.allocate(record->depth);
    2.11      if (!record->slots) {
    2.12 @@ -80,7 +80,7 @@
    2.13      }
    2.14  
    2.15      bool hadOops = false;
    2.16 -    for (size_t i = 0; i < oopMap_.size(); i++) {
    2.17 +    for (size_t i = 0; i < oopMap_.length(); i++) {
    2.18          bool bit = oopMap_[i];
    2.19          record->slots[i] = bit;
    2.20          hadOops |= bit;
    2.21 @@ -89,6 +89,6 @@
    2.22      if (!hadOops)
    2.23          return;
    2.24  
    2.25 -    oopRecords_.push_back(record);
    2.26 +    oom_ &= oopRecords_.append(record);
    2.27  }
    2.28  
     3.1 --- a/jitcraft/BytecodeEmitter.h	Sat Jul 07 21:01:39 2012 -0700
     3.2 +++ b/jitcraft/BytecodeEmitter.h	Sat Jul 07 21:08:47 2012 -0700
     3.3 @@ -21,7 +21,6 @@
     3.4  
     3.5  #include <assert.h>
     3.6  #include <limits.h>
     3.7 -#include <vector>
     3.8  #include "Opcodes.h"
     3.9  #include "NameBinding.h"
    3.10  #include "Handles.h"
    3.11 @@ -31,7 +30,7 @@
    3.12  class Type;
    3.13  class Map;
    3.14  
    3.15 -typedef std::vector<ScopedRoot<Object> *> ObjectList;
    3.16 +typedef PoolList<ScopedRoot<Object> *> ObjectList;
    3.17  
    3.18  struct OopRecord : public PoolObject
    3.19  {
    3.20 @@ -59,8 +58,8 @@
    3.21      bool oom_;
    3.22      unsigned maxStackDepth_;
    3.23      ObjectList objects_;
    3.24 -    std::vector<bool> oopMap_;
    3.25 -    std::vector<OopRecord *> oopRecords_;
    3.26 +    PoolList<bool> oopMap_;
    3.27 +    PoolList<OopRecord *> oopRecords_;
    3.28  
    3.29    private:
    3.30      // The maximum size of a code object must be such that the distance between
    3.31 @@ -103,18 +102,18 @@
    3.32  
    3.33          writeUint8(op);
    3.34          for (int i = 0; i < OpcodeInfo[op].nuses; i++)
    3.35 -            oopMap_.pop_back();
    3.36 +            oopMap_.pop();
    3.37          for (int i = 0; i < OpcodeInfo[op].ndefs; i++)
    3.38 -            oopMap_.push_back(false);
    3.39 -        if (oopMap_.size() > maxStackDepth_)
    3.40 -            maxStackDepth_ = oopMap_.size();
    3.41 +            oopMap_.append(false);
    3.42 +        if (oopMap_.length() > maxStackDepth_)
    3.43 +            maxStackDepth_ = oopMap_.length();
    3.44      }
    3.45      void writeObject(Object *obj) {
    3.46 -        writeUint32(objects_.size());
    3.47 +        writeUint32(objects_.length());
    3.48          ScopedRoot<Object> *root = new ScopedRoot<Object>(obj);
    3.49          if (!root)
    3.50              oom_ = true;
    3.51 -        objects_.push_back(root);
    3.52 +        oom_ &= objects_.append(root);
    3.53      }
    3.54  
    3.55      int position() const {
    3.56 @@ -135,7 +134,7 @@
    3.57          return oom_;
    3.58      }
    3.59      unsigned stackDepth() const {
    3.60 -        return oopMap_.size();
    3.61 +        return oopMap_.length();
    3.62      }
    3.63      unsigned maxStackDepth() const {
    3.64          return maxStackDepth_;
    3.65 @@ -143,14 +142,14 @@
    3.66      const ObjectList *objects() const {
    3.67          return &objects_;
    3.68      }
    3.69 -    std::vector<OopRecord *> *oopRecords() {
    3.70 +    PoolList<OopRecord *> *oopRecords() {
    3.71          return &oopRecords_;
    3.72      }
    3.73  
    3.74      void drop(unsigned amt) {
    3.75          assert(amt <= stackDepth());
    3.76          for (unsigned i = 0; i < amt; i++)
    3.77 -            oopMap_.pop_back();
    3.78 +            oopMap_.pop();
    3.79      }
    3.80  
    3.81    public:
    3.82 @@ -229,12 +228,12 @@
    3.83      void markOop(unsigned depth, bool oop = true) {
    3.84          if (oom_)
    3.85              return;
    3.86 -        oopMap_[oopMap_.size() - depth] = oop;
    3.87 +        oopMap_[oopMap_.length() - depth] = oop;
    3.88      }
    3.89      bool getOop(unsigned depth) {
    3.90          if (oom_)
    3.91              return false;
    3.92 -        return oopMap_[oopMap_.size() - depth];
    3.93 +        return oopMap_[oopMap_.length() - depth];
    3.94      }
    3.95  
    3.96      // Mark the current bytecode position as either re-entrant (meaning, it
     4.1 --- a/jitcraft/Parser.h	Sat Jul 07 21:01:39 2012 -0700
     4.2 +++ b/jitcraft/Parser.h	Sat Jul 07 21:08:47 2012 -0700
     4.3 @@ -19,7 +19,6 @@
     4.4  #define _include_jitcraft_parser_h_
     4.5  
     4.6  #include <stdio.h>
     4.7 -#include <vector>
     4.8  #include "AST.h"
     4.9  #include "Scanner.h"
    4.10  #include "Scopes.h"
     5.1 --- a/jitcraft/Scopes.cpp	Sat Jul 07 21:01:39 2012 -0700
     5.2 +++ b/jitcraft/Scopes.cpp	Sat Jul 07 21:08:47 2012 -0700
     5.3 @@ -38,8 +38,8 @@
     5.4  bool
     5.5  Scope::initialize()
     5.6  {
     5.7 -    if (enclosing_)
     5.8 -        enclosing_->children_.push_back(this);
     5.9 +    if (enclosing_ && !enclosing_->children_.append(this))
    5.10 +        return false;
    5.11      return true;
    5.12  }
    5.13  
    5.14 @@ -48,11 +48,13 @@
    5.15  {
    5.16      assert(empty());
    5.17  
    5.18 -    assert(enclosing_->children_[enclosing_->children_.size() - 1] == this);
    5.19 -    enclosing_->children_.pop_back();
    5.20 +    assert(enclosing_->children_[enclosing_->children_.length() - 1] == this);
    5.21 +    enclosing_->children_.pop();
    5.22  
    5.23 -    for (size_t i = 0; i < children_.size(); i++)
    5.24 -        enclosing_->children_.push_back(children_[i]);
    5.25 +    // OOM here is swallowed and checked after compilation.
    5.26 +    // :TODO: make the above true.
    5.27 +    for (size_t i = 0; i < children_.length(); i++)
    5.28 +        enclosing_->children_.append(children_[i]);
    5.29  }
    5.30  
    5.31  Scope *
    5.32 @@ -68,7 +70,7 @@
    5.33  BoundName *
    5.34  Scope::localLookup(Handle<String> name)
    5.35  {
    5.36 -    for (size_t i = 0; i < names_.size(); i++) {
    5.37 +    for (size_t i = 0; i < names_.length(); i++) {
    5.38          if (names_[i]->name() == name)
    5.39              return names_[i];
    5.40      }
    5.41 @@ -91,7 +93,8 @@
    5.42      assert(!localLookup(name));
    5.43      
    5.44      Variable *var = new (pool_) Variable(this, name, pos);
    5.45 -    names_.push_back(var);
    5.46 +    if (!names_.append(var))
    5.47 +        return NULL;
    5.48      return var;
    5.49  }
    5.50  
    5.51 @@ -100,8 +103,10 @@
    5.52  {
    5.53      assert(kind() == FUNCTION);
    5.54      Variable *var = declareVariable(name, pos);
    5.55 -    names_.push_back(var);
    5.56 -    parameters_.push_back(var);
    5.57 +    if (!names_.append(var))
    5.58 +        return NULL;
    5.59 +    if (!parameters_.append(var))
    5.60 +        return NULL;
    5.61      return var;
    5.62  }
    5.63  
    5.64 @@ -112,7 +117,8 @@
    5.65      assert(kind() == GLOBAL);
    5.66  
    5.67      NamedFunction *fun = new (pool_) NamedFunction(this, name, pos);
    5.68 -    names_.push_back(fun);
    5.69 +    if (!names_.append(fun))
    5.70 +        return NULL;
    5.71      return fun;
    5.72  }
    5.73  
    5.74 @@ -120,7 +126,8 @@
    5.75  Scope::declareEnum(Handle<String> name, const SourcePosition &pos)
    5.76  {
    5.77      NamedEnum *e = new (pool_) NamedEnum(this, name, pos);
    5.78 -    names_.push_back(e);
    5.79 +    if (!names_.append(e))
    5.80 +        return NULL;
    5.81      return e;
    5.82  }
    5.83  
    5.84 @@ -128,7 +135,8 @@
    5.85  Scope::declareConstant(Handle<String> name, const SourcePosition &pos)
    5.86  {
    5.87      NamedConstant *constant = new (pool_) NamedConstant(this, name, pos);
    5.88 -    names_.push_back(constant);
    5.89 +    if (!names_.append(constant))
    5.90 +        return NULL;
    5.91      return constant;
    5.92  }
    5.93  
    5.94 @@ -137,12 +145,12 @@
    5.95  {
    5.96      assert(kind() == GLOBAL);
    5.97  
    5.98 -    for (size_t i = 0; i < children_.size(); i++) {
    5.99 +    for (size_t i = 0; i < children_.length(); i++) {
   5.100          assert(children_[i]->kind() == FUNCTION);
   5.101          children_[i]->allocate();
   5.102      }
   5.103  
   5.104 -    for (size_t i = 0; i < names_.size(); i++) {
   5.105 +    for (size_t i = 0; i < names_.length(); i++) {
   5.106          BoundName *name = names_[i];
   5.107          
   5.108          if (name->kind() == BoundName::FUNCTION) {
   5.109 @@ -166,19 +174,19 @@
   5.110  Scope::allocate()
   5.111  {
   5.112      maxContainedLocals_ = 0;
   5.113 -    for (size_t i = 0; i < children_.size(); i++) {
   5.114 +    for (size_t i = 0; i < children_.length(); i++) {
   5.115          Scope *scope = children_[i];
   5.116          scope->allocate();
   5.117          if (scope->maxContainedLocals() > maxContainedLocals_)
   5.118              maxContainedLocals_ = scope->maxContainedLocals();
   5.119      }
   5.120  
   5.121 -    for (size_t i = 0; i < parameters_.size(); i++)
   5.122 +    for (size_t i = 0; i < parameters_.length(); i++)
   5.123          parameters_[i]->allocate(Variable::PARAMETER, i);
   5.124  
   5.125      if (lifoSlot_)
   5.126          allocate(lifoSlot_);
   5.127 -    for (size_t i = 0; i < names_.size(); i++) {
   5.128 +    for (size_t i = 0; i < names_.length(); i++) {
   5.129          if (names_[i]->kind() != BoundName::VARIABLE)
   5.130              continue;
   5.131  
     6.1 --- a/jitcraft/Scopes.h	Sat Jul 07 21:01:39 2012 -0700
     6.2 +++ b/jitcraft/Scopes.h	Sat Jul 07 21:08:47 2012 -0700
     6.3 @@ -18,7 +18,6 @@
     6.4  #ifndef _include_jitcraft_scopes_h_
     6.5  #define _include_jitcraft_scopes_h_
     6.6  
     6.7 -#include <vector>
     6.8  #include "PoolAllocator.h"
     6.9  #include "AST.h"
    6.10  #include "NameBinding.h"
    6.11 @@ -28,16 +27,16 @@
    6.12  class Scope : public PoolObject
    6.13  {
    6.14      PoolAllocator &pool_;
    6.15 -    std::vector<BoundName *> names_;
    6.16 -    std::vector<Scope *> children_;
    6.17 -    std::vector<Variable *> parameters_;
    6.18 +    PoolList<BoundName *> names_;
    6.19 +    PoolList<Scope *> children_;
    6.20 +    PoolList<Variable *> parameters_;
    6.21      unsigned locals_;
    6.22      unsigned maxContainedLocals_;
    6.23      unsigned numFunctions_;
    6.24      Variable *lifoSlot_;
    6.25      
    6.26      bool empty() const {
    6.27 -        return names_.size() == 0;
    6.28 +        return names_.length() == 0;
    6.29      }
    6.30      void unlink();
    6.31  
    6.32 @@ -68,7 +67,7 @@
    6.33          return numFunctions_;
    6.34      }
    6.35      unsigned numArguments() const {
    6.36 -        return parameters_.size();
    6.37 +        return parameters_.length();
    6.38      }
    6.39      Variable *getArgument(size_t index) {
    6.40          return parameters_[index];
     7.1 --- a/jitcraft/Vector.h	Sat Jul 07 21:01:39 2012 -0700
     7.2 +++ b/jitcraft/Vector.h	Sat Jul 07 21:08:47 2012 -0700
     7.3 @@ -47,6 +47,11 @@
     7.4          nitems++;
     7.5          return true;
     7.6      }
     7.7 +    void pop() {
     7.8 +        assert(nitems);
     7.9 +        data[nitems - 1].~T();
    7.10 +        nitems--;
    7.11 +    }
    7.12      size_t length() const {
    7.13          return nitems;
    7.14      }
    7.15 @@ -59,10 +64,10 @@
    7.16          return data[i];
    7.17      }
    7.18      T& operator [](size_t i) {
    7.19 -        return get(i);
    7.20 +        return at(i);
    7.21      }
    7.22      const T& operator [](size_t i) const {
    7.23 -        return get(i);
    7.24 +        return at(i);
    7.25      }
    7.26      void clear() {
    7.27          nitems = 0;