Replaced android::Vector with std::vector.

Change-Id: I4c6abd964dc4b1412ec2e592fc8e835fecfe53f6
diff --git a/Android.mk b/Android.mk
index 685e555..5e4f82e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,7 +1,7 @@
 
 LOCAL_PATH:=$(call my-dir)
 
-rs_base_CFLAGS := -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fno-exceptions
+rs_base_CFLAGS := -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fno-exceptions -std=c++11
 ifeq ($(TARGET_BUILD_PDK), true)
   rs_base_CFLAGS += -D__RS_PDK__
 endif
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 86e61e1..9191488 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -176,7 +176,7 @@
         // library fallback path. Those applications don't have a private
         // library path, so they need to install to the system directly.
         // Note that this is really just a testing path.
-        android::String8 scriptSONameSystem("/system/lib/librs.");
+        std::string scriptSONameSystem("/system/lib/librs.");
         scriptSONameSystem.append(resName);
         scriptSONameSystem.append(".so");
         loaded = loadSOHelper(scriptSONameSystem.c_str(), cacheDir,
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index 4eb9e9d..1d26f59 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -126,11 +126,11 @@
 
 
 void CpuScriptGroupImpl::execute() {
-    Vector<Allocation *> ins;
-    Vector<bool> inExts;
-    Vector<Allocation *> outs;
-    Vector<bool> outExts;
-    Vector<const ScriptKernelID *> kernels;
+    std::vector<Allocation *> ins;
+    std::vector<char> inExts;
+    std::vector<Allocation *> outs;
+    std::vector<char> outExts;
+    std::vector<const ScriptKernelID *> kernels;
     bool fieldDep = false;
 
     for (size_t ct=0; ct < mSG->mNodes.size(); ct++) {
@@ -196,11 +196,11 @@
             rsAssert((k->mHasKernelOutput == (aout != NULL)) &&
                      (k->mHasKernelInput == (ain != NULL)));
 
-            ins.add(ain);
-            inExts.add(inExt);
-            outs.add(aout);
-            outExts.add(outExt);
-            kernels.add(k);
+            ins.push_back(ain);
+            inExts.push_back(inExt);
+            outs.push_back(aout);
+            outExts.push_back(outExt);
+            kernels.push_back(k);
         }
 
     }
@@ -237,10 +237,16 @@
         }
     } else {
         ScriptList sl;
-        sl.ins = ins.array();
-        sl.outs = outs.array();
-        sl.kernels = kernels.array();
-        sl.count = kernels.size();
+
+        /*
+         * TODO: This is a hacky way of doing this and should be replaced by a
+         *       call to std::vector's data() member once we have a C++11
+         *       version of the STL.
+         */
+        sl.ins     = &ins.front();
+        sl.outs    = &outs.front();
+        sl.kernels = &kernels.front();
+        sl.count   = kernels.size();
 
         uint32_t inLen;
         const Allocation **ains;
@@ -254,25 +260,27 @@
             ains  = const_cast<const Allocation**>(&ins[0]);
         }
 
-        Vector<const void *> usrPtrs;
-        Vector<const void *> fnPtrs;
-        Vector<uint32_t> sigs;
+        std::vector<const void *> usrPtrs;
+        std::vector<const void *> fnPtrs;
+        std::vector<uint32_t> sigs;
         for (size_t ct=0; ct < kernels.size(); ct++) {
             Script *s = kernels[ct]->mScript;
             RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
 
             si->forEachKernelSetup(kernels[ct]->mSlot, &mtls);
-            fnPtrs.add((void *)mtls.kernel);
-            usrPtrs.add(mtls.fep.usr);
-            sigs.add(mtls.fep.usrLen);
+            fnPtrs.push_back((void *)mtls.kernel);
+            usrPtrs.push_back(mtls.fep.usr);
+            sigs.push_back(mtls.fep.usrLen);
             si->preLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct],
                           mtls.fep.usr, mtls.fep.usrLen, NULL);
         }
-        sl.sigs = sigs.array();
-        sl.usrPtrs = usrPtrs.array();
-        sl.fnPtrs = fnPtrs.array();
-        sl.inExts = inExts.array();
-        sl.outExts = outExts.array();
+
+        sl.sigs    = &sigs.front();
+        sl.usrPtrs = &usrPtrs.front();
+        sl.fnPtrs  = &fnPtrs.front();
+
+        sl.inExts  = (bool*)&inExts.front();
+        sl.outExts = (bool*)&outExts.front();
 
         Script *s = kernels[0]->mScript;
         RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp
index b7c7f2e..419422a 100644
--- a/driver/rsdBcc.cpp
+++ b/driver/rsdBcc.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <vector>
+
 #include "../cpu_ref/rsd_cpu.h"
 
 #include "rsdCore.h"
@@ -26,7 +28,6 @@
 #include "rsScriptC.h"
 
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
-#include "utils/Vector.h"
 #include "utils/Timers.h"
 #include "utils/StopWatch.h"
 #endif
diff --git a/driver/rsdMeshObj.cpp b/driver/rsdMeshObj.cpp
index 66c3b18..5837c26 100644
--- a/driver/rsdMeshObj.cpp
+++ b/driver/rsdMeshObj.cpp
@@ -114,7 +114,7 @@
             mAttribs[userNum].stride = stride;
             String8 tmp(RS_SHADER_ATTR);
             tmp.append(elem->mHal.state.fieldNames[fieldI]);
-            mAttribs[userNum].name.setTo(tmp.string());
+            mAttribs[userNum].name = tmp.string();
 
             // Remember which allocation this attribute came from
             mAttribAllocationIndex[userNum] = ct;
diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp
index 0b182ff..8a0b015 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -41,13 +41,13 @@
     init(textureNames, textureNamesCount, textureNamesLength);
 
     for(size_t i=0; i < textureNamesCount; i++) {
-        mTextureNames.push(String8(textureNames[i], textureNamesLength[i]));
+        mTextureNames.push_back(String8(textureNames[i], textureNamesLength[i]));
     }
 }
 
 RsdShader::~RsdShader() {
     for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
-        StateBasedKey *state = mStateBasedShaders.itemAt(i);
+        StateBasedKey *state = mStateBasedShaders[i];
         if (state->mShaderID) {
             glDeleteShader(state->mShaderID);
         }
@@ -76,7 +76,7 @@
     RsdShader::StateBasedKey *returnKey = NULL;
 
     for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
-        returnKey = mStateBasedShaders.itemAt(i);
+        returnKey = mStateBasedShaders[i];
 
         for (uint32_t ct = 0; ct < mRSProgram->mHal.state.texturesCount; ct ++) {
             uint32_t texType = 0;
@@ -108,7 +108,7 @@
     // We have not created a shader for this particular state yet
     state = new StateBasedKey(mTextureCount);
     mCurrentState = state;
-    mStateBasedShaders.add(state);
+    mStateBasedShaders.push_back(state);
     createShader();
     loadShader(rsc);
     return mCurrentState->mShaderID;
diff --git a/driver/rsdShader.h b/driver/rsdShader.h
index fba1790..d5076e3 100644
--- a/driver/rsdShader.h
+++ b/driver/rsdShader.h
@@ -49,7 +49,7 @@
     // Add ability to get all ID's to clean up the cached program objects
     uint32_t getStateBasedIDCount() const { return mStateBasedShaders.size(); }
     uint32_t getStateBasedID(uint32_t index) const {
-        return mStateBasedShaders.itemAt(index)->mShaderID;
+        return mStateBasedShaders[index]->mShaderID;
     }
 
     uint32_t getAttribCount() const {return mAttribCount;}
@@ -116,9 +116,9 @@
     android::String8 *mUniformNames;
     uint32_t *mUniformArraySizes;
 
-    android::Vector<android::String8> mTextureNames;
+    std::vector<android::String8> mTextureNames;
 
-    android::Vector<StateBasedKey*> mStateBasedShaders;
+    std::vector<StateBasedKey*> mStateBasedShaders;
 
     int32_t mTextureUniformIndexStart;
 
@@ -133,7 +133,3 @@
 };
 
 #endif //ANDROID_RSD_SHADER_H
-
-
-
-
diff --git a/driver/rsdShaderCache.cpp b/driver/rsdShaderCache.cpp
index 69b43fc..9eb1631 100644
--- a/driver/rsdShaderCache.cpp
+++ b/driver/rsdShaderCache.cpp
@@ -29,7 +29,7 @@
 
 
 RsdShaderCache::RsdShaderCache() {
-    mEntries.setCapacity(16);
+    mEntries.reserve(16);
     mVertexDirty = true;
     mFragmentDirty = true;
 }
@@ -132,7 +132,7 @@
     ProgramEntry *e = new ProgramEntry(vtx->getAttribCount(),
                                        vtx->getUniformCount(),
                                        frag->getUniformCount());
-    mEntries.push(e);
+    mEntries.push_back(e);
     mCurrent = e;
     e->vtx = vID;
     e->frag = fID;
@@ -228,7 +228,7 @@
     return true;
 }
 
-int32_t RsdShaderCache::vtxAttribSlot(const String8 &attrName) const {
+int32_t RsdShaderCache::vtxAttribSlot(const std::string &attrName) const {
     for (uint32_t ct=0; ct < mCurrent->vtxAttrCount; ct++) {
         if (attrName == mCurrent->vtxAttrs[ct].name) {
             return mCurrent->vtxAttrs[ct].slot;
@@ -238,46 +238,45 @@
 }
 
 void RsdShaderCache::cleanupVertex(RsdShader *s) {
-    int32_t numEntries = (int32_t)mEntries.size();
     uint32_t numShaderIDs = s->getStateBasedIDCount();
     for (uint32_t sId = 0; sId < numShaderIDs; sId ++) {
         uint32_t id = s->getStateBasedID(sId);
-        for (int32_t ct = 0; ct < numEntries; ct ++) {
-            if (mEntries[ct]->vtx == id) {
-                glDeleteProgram(mEntries[ct]->program);
 
-                delete mEntries[ct];
-                mEntries.removeAt(ct);
-                numEntries = (int32_t)mEntries.size();
-                ct --;
+        for (auto entry = mEntries.begin(); entry != mEntries.end();) {
+            if ((*entry)->vtx == id) {
+                glDeleteProgram((*entry)->program);
+
+                delete *entry;
+                entry = mEntries.erase(entry);
+            } else {
+                entry++;
             }
         }
     }
 }
 
 void RsdShaderCache::cleanupFragment(RsdShader *s) {
-    int32_t numEntries = (int32_t)mEntries.size();
     uint32_t numShaderIDs = s->getStateBasedIDCount();
     for (uint32_t sId = 0; sId < numShaderIDs; sId ++) {
         uint32_t id = s->getStateBasedID(sId);
-        for (int32_t ct = 0; ct < numEntries; ct ++) {
-            if (mEntries[ct]->frag == id) {
-                glDeleteProgram(mEntries[ct]->program);
 
-                delete mEntries[ct];
-                mEntries.removeAt(ct);
-                numEntries = (int32_t)mEntries.size();
-                ct --;
+        for (auto entry = mEntries.begin(); entry != mEntries.end();) {
+            if ((*entry)->frag == id) {
+                glDeleteProgram((*entry)->program);
+
+                delete *entry;
+                entry = mEntries.erase(entry);
+            } else {
+                entry++;
             }
         }
     }
 }
 
 void RsdShaderCache::cleanupAll() {
-    for (uint32_t ct=0; ct < mEntries.size(); ct++) {
-        glDeleteProgram(mEntries[ct]->program);
-        free(mEntries[ct]);
+    for (auto entry : mEntries) {
+        glDeleteProgram(entry->program);
+        delete entry;
     }
     mEntries.clear();
 }
-
diff --git a/driver/rsdShaderCache.h b/driver/rsdShaderCache.h
index 6de1d63..e782fe5 100644
--- a/driver/rsdShaderCache.h
+++ b/driver/rsdShaderCache.h
@@ -17,6 +17,9 @@
 #ifndef ANDROID_RSD_SHADER_CACHE_H
 #define ANDROID_RSD_SHADER_CACHE_H
 
+#include <string>
+#include <vector>
+
 namespace android {
 namespace renderscript {
 
@@ -27,7 +30,6 @@
 
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
 #include <utils/String8.h>
-#include <utils/Vector.h>
 #else
 #include "rsUtils.h"
 #endif
@@ -58,7 +60,7 @@
 
     void cleanupAll();
 
-    int32_t vtxAttribSlot(const android::String8 &attrName) const;
+    int32_t vtxAttribSlot(const std::string &attrName) const;
     int32_t vtxUniformSlot(uint32_t a) const {return mCurrent->vtxUniforms[a].slot;}
     uint32_t vtxUniformSize(uint32_t a) const {return mCurrent->vtxUniforms[a].arraySize;}
     int32_t fragUniformSlot(uint32_t a) const {return mCurrent->fragUniforms[a].slot;}
@@ -143,7 +145,7 @@
         UniformData *fragUniforms;
         bool *fragUniformIsSTO;
     };
-    android::Vector<ProgramEntry*> mEntries;
+    std::vector<ProgramEntry*> mEntries;
     ProgramEntry *mCurrent;
 
     bool hasArrayUniforms(RsdShader *vtx, RsdShader *frag);
@@ -156,7 +158,3 @@
 
 
 #endif //ANDROID_RSD_SHADER_CACHE_H
-
-
-
-
diff --git a/driver/rsdVertexArray.cpp b/driver/rsdVertexArray.cpp
index 4e293f6..d0a9b3e 100644
--- a/driver/rsdVertexArray.cpp
+++ b/driver/rsdVertexArray.cpp
@@ -48,7 +48,7 @@
     stride = 0;
     ptr = NULL;
     normalized = false;
-    name.setTo("");
+    name = "";
 }
 
 void RsdVertexArray::Attrib::set(uint32_t type, uint32_t size, uint32_t stride,
@@ -60,7 +60,7 @@
     this->offset = offset;
     this->normalized = normalized;
     this->stride = stride;
-    this->name.setTo(name);
+    this->name = name;
 }
 
 void RsdVertexArray::logAttrib(uint32_t idx, uint32_t slot) const {
@@ -69,7 +69,7 @@
     }
     ALOGV("va %i: slot=%i name=%s buf=%i ptr=%p size=%i  type=0x%x  stride=0x%x  norm=%i  offset=0x%p",
           idx, slot,
-          mAttribs[idx].name.string(),
+          mAttribs[idx].name.c_str(),
           mAttribs[idx].buffer,
           mAttribs[idx].ptr,
           mAttribs[idx].size,
@@ -135,4 +135,3 @@
         mAttrsEnabled[ct] = false;
     }
 }
-
diff --git a/driver/rsdVertexArray.h b/driver/rsdVertexArray.h
index 975121b..1bafe3b 100644
--- a/driver/rsdVertexArray.h
+++ b/driver/rsdVertexArray.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_RSD_VERTEX_ARRAY_H
 #define ANDROID_RSD_VERTEX_ARRAY_H
 
+#include <string>
+
 #include "rsUtils.h"
 
 namespace android {
@@ -39,7 +41,7 @@
         uint32_t size;
         uint32_t stride;
         bool normalized;
-        android::String8 name;
+        std::string name;
 
         Attrib();
         void clear();
@@ -74,6 +76,3 @@
 
 
 #endif //ANDROID_RSD_VERTEX_ARRAY_H
-
-
-
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index 59967e9..f9e4266 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -223,34 +223,40 @@
     }
 
     if (y >= mHal.drvState.lod[0].dimY) {
-        rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "subElementData X offset out of range.");
         return;
     }
 
     if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
-        rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "subElementData component out of range.");
         return;
     }
 
     const Element * e = mHal.state.type->getElement()->getField(cIdx);
-    uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
+    uint32_t elemArraySize =
+        mHal.state.type->getElement()->getFieldArraySize(cIdx);
     if (sizeBytes != e->getSizeBytes() * elemArraySize) {
         rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
         return;
     }
 
-    rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes);
+    rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx,
+                                             sizeBytes);
     sendDirty(rsc);
 }
 
 void Allocation::addProgramToDirty(const Program *p) {
-    mToDirtyList.push(p);
+    mToDirtyList.push_back(p);
 }
 
 void Allocation::removeProgramToDirty(const Program *p) {
-    for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
-        if (mToDirtyList[ct] == p) {
-            mToDirtyList.removeAt(ct);
+    for (auto entryIter = mToDirtyList.begin(), endIter = mToDirtyList.end();
+         entryIter != endIter; entryIter++) {
+
+        if (p == *entryIter) {
+            mToDirtyList.erase(entryIter);
             return;
         }
     }
@@ -268,7 +274,8 @@
         }
     }
     ALOGV("%s allocation ptr=%p  mUsageFlags=0x04%x, mMipmapControl=0x%04x",
-         prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl);
+          prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags,
+          mHal.state.mipmapControl);
 }
 
 uint32_t Allocation::getPackedSize() const {
diff --git a/rsAllocation.h b/rsAllocation.h
index f197efc..47344d8 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -170,7 +170,7 @@
     bool hasSameDims(const Allocation *Other) const;
 
 protected:
-    Vector<const Program *> mToDirtyList;
+    std::vector<const Program *> mToDirtyList;
     ObjectBaseRef<const Type> mType;
     void setType(const Type *t) {
         mType.set(t);
diff --git a/rsContext.cpp b/rsContext.cpp
index d3d8349..410ab35 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -743,13 +743,15 @@
 void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) {
     rsAssert(!obj->getName());
     obj->setName(name, len);
-    mNames.add(obj);
+    mNames.push_back(obj);
 }
 
 void Context::removeName(ObjectBase *obj) {
-    for (size_t ct=0; ct < mNames.size(); ct++) {
-        if (obj == mNames[ct]) {
-            mNames.removeAt(ct);
+    for (auto nameIter = mNames.begin(), endIter = mNames.end();
+         nameIter != endIter; nameIter++) {
+
+        if (obj == *nameIter) {
+            mNames.erase(nameIter);
             return;
         }
     }
@@ -984,4 +986,3 @@
     ObjectBase *ob = static_cast<ObjectBase *>(obj);
     (*name) = ob->getName();
 }
-
diff --git a/rsContext.h b/rsContext.h
index b382358..f750670 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -297,7 +297,7 @@
     bool mHasSurface;
     bool mIsContextLite;
 
-    Vector<ObjectBase *> mNames;
+    std::vector<ObjectBase *> mNames;
 
     uint64_t mTimers[_RS_TIMER_TOTAL];
     Timers mTimerActive;
diff --git a/rsCppUtils.h b/rsCppUtils.h
index 71cf077..3157857 100644
--- a/rsCppUtils.h
+++ b/rsCppUtils.h
@@ -20,7 +20,6 @@
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
 #include <utils/Log.h>
 #include <utils/String8.h>
-#include <utils/Vector.h>
 #include <cutils/atomic.h>
 #endif
 
@@ -54,96 +53,6 @@
 #define ALOGV(...) \
     __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__);
 
-namespace android {
-
-    // server has no Vector or String8 classes; implement on top of STL
-    class String8: public std::string {
-    public:
-    String8(const char *ptr) : std::string(ptr) {
-
-        }
-    String8(const char *ptr, size_t len) : std::string(ptr, len) {
-
-        }
-    String8() : std::string() {
-
-        }
-
-        const char* string() const {
-            return this->c_str();
-        }
-
-        void setTo(const char* str, ssize_t len) {
-            this->assign(str, len);
-        }
-        void setTo(const char* str) {
-            this->assign(str);
-        }
-        String8 getPathDir(void) const {
-            const char* cp;
-            const char*const str = this->c_str();
-
-            cp = strrchr(str, OS_PATH_SEPARATOR);
-            if (cp == NULL)
-                return String8("");
-            else
-                return String8(str, cp - str);
-        }
-    };
-
-    template <class T> class Vector: public std::vector<T> {
-    public:
-        void push(T obj) {
-            this->push_back(obj);
-        }
-        void removeAt(uint32_t index) {
-            this->erase(this->begin() + index);
-        }
-        ssize_t add(const T& obj) {
-            this->push_back(obj);
-            return this->size() - 1;
-        }
-        void setCapacity(ssize_t capacity) {
-            this->resize(capacity);
-        }
-
-        T* editArray() {
-            return (T*)(this->begin());
-        }
-
-        const T* array() {
-            return (const T*)(this->begin());
-        }
-
-    };
-
-    template<> class Vector<bool>: public std::vector<char> {
-    public:
-        void push(bool obj) {
-            this->push_back(obj);
-        }
-        void removeAt(uint32_t index) {
-            this->erase(this->begin() + index);
-        }
-        ssize_t add(const bool& obj) {
-            this->push_back(obj);
-            return this->size() - 1;
-        }
-        void setCapacity(ssize_t capacity) {
-            this->resize(capacity);
-        }
-
-        bool* editArray() {
-            return (bool*)(this->begin());
-        }
-
-        const bool* array() {
-            return (const bool*)(this->begin());
-        }
-    };
-
-}
-
 typedef int64_t nsecs_t;  // nano-seconds
 
 enum {
@@ -286,5 +195,3 @@
 }
 
 #endif //ANDROID_RS_OBJECT_BASE_H
-
-
diff --git a/rsDevice.cpp b/rsDevice.cpp
index 2688890..1ba005a 100644
--- a/rsDevice.cpp
+++ b/rsDevice.cpp
@@ -28,14 +28,16 @@
 }
 
 void Device::addContext(Context *rsc) {
-    mContexts.push(rsc);
+    mContexts.push_back(rsc);
 }
 
 void Device::removeContext(Context *rsc) {
-    for (size_t idx=0; idx < mContexts.size(); idx++) {
-        if (mContexts[idx] == rsc) {
-            mContexts.removeAt(idx);
-            break;
+    for (auto ctxIter = mContexts.begin(), endIter = mContexts.end();
+         ctxIter != endIter; ctxIter++) {
+
+        if (rsc == *ctxIter) {
+            mContexts.erase(ctxIter);
+            return;
         }
     }
 }
@@ -58,4 +60,3 @@
     }
     rsAssert(0);
 }
-
diff --git a/rsDevice.h b/rsDevice.h
index ffb514b..5961336 100644
--- a/rsDevice.h
+++ b/rsDevice.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_RS_DEVICE_H
 #define ANDROID_RS_DEVICE_H
 
+#include <vector>
+
 #include "rsUtils.h"
 
 // ---------------------------------------------------------------------------
@@ -36,7 +38,7 @@
     bool mForceSW;
 
 protected:
-    Vector<Context *> mContexts;
+    std::vector<Context *> mContexts;
 };
 
 }
diff --git a/rsElement.cpp b/rsElement.cpp
index f7b064a..0da8096 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -42,10 +42,14 @@
 }
 
 void Element::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateElement.mElements.size(); ct++) {
-        if (mRSC->mStateElement.mElements[ct] == this) {
-            mRSC->mStateElement.mElements.removeAt(ct);
-            break;
+    auto &elements = mRSC->mStateElement.mElements;
+
+    for (auto elIter = elements.begin(), endIter = elements.end();
+         elIter != endIter; elIter++) {
+
+        if (this == *elIter) {
+            elements.erase(elIter);
+            return;
         }
     }
 }
@@ -264,7 +268,7 @@
 
 
     ObjectBase::asyncLock();
-    rsc->mStateElement.mElements.push(e);
+    rsc->mStateElement.mElements.push_back(e);
     ObjectBase::asyncUnlock();
 
     return returnRef;
@@ -339,7 +343,7 @@
     e->compute();
 
     ObjectBase::asyncLock();
-    rsc->mStateElement.mElements.push(e);
+    rsc->mStateElement.mElements.push_back(e);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsElement.h b/rsElement.h
index 5a3bc13..2ae9404 100644
--- a/rsElement.h
+++ b/rsElement.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_STRUCTURED_ELEMENT_H
 #define ANDROID_STRUCTURED_ELEMENT_H
 
+#include <vector>
+
 #include "rsComponent.h"
 #include "rsUtils.h"
 #include "rsDefines.h"
@@ -170,7 +172,7 @@
     ~ElementState();
 
     // Cache of all existing elements.
-    Vector<Element *> mElements;
+    std::vector<Element *> mElements;
 };
 
 
diff --git a/rsFileA3D.cpp b/rsFileA3D.cpp
index a589033..ef5730f 100644
--- a/rsFileA3D.cpp
+++ b/rsFileA3D.cpp
@@ -87,7 +87,7 @@
             entry->mLength = headerStream->loadU32();
         }
         entry->mRsObj = NULL;
-        mIndex.push(entry);
+        mIndex.push_back(entry);
     }
 }
 
@@ -379,7 +379,7 @@
     indexEntry->mType = obj->getClassId();
     indexEntry->mOffset = mWriteStream->getPos();
     indexEntry->mRsObj = obj;
-    mWriteIndex.push(indexEntry);
+    mWriteIndex.push_back(indexEntry);
     obj->serialize(con, mWriteStream);
     indexEntry->mLength = mWriteStream->getPos() - indexEntry->mOffset;
     mWriteStream->align(4);
diff --git a/rsFileA3D.h b/rsFileA3D.h
index 8bf36b9..0c8b3d6 100644
--- a/rsFileA3D.h
+++ b/rsFileA3D.h
@@ -88,15 +88,13 @@
     Asset *mAsset;
 
     OStream *mWriteStream;
-    Vector<A3DIndexEntry*> mWriteIndex;
+    std::vector<A3DIndexEntry*> mWriteIndex;
 
     IStream *mReadStream;
-    Vector<A3DIndexEntry*> mIndex;
+    std::vector<A3DIndexEntry*> mIndex;
 };
 
 
 }
 }
 #endif //ANDROID_RS_FILE_A3D_H
-
-
diff --git a/rsFont.cpp b/rsFont.cpp
index 8feef2d..71399af 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -33,7 +33,7 @@
 using namespace android;
 using namespace android::renderscript;
 
-Font::Font(Context *rsc) : ObjectBase(rsc), mCachedGlyphs(NULL) {
+Font::Font(Context *rsc) : ObjectBase(rsc) {
     mInitialized = false;
     mHasKerning = false;
     mFace = NULL;
@@ -76,17 +76,21 @@
 }
 
 void Font::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) {
-        if (mRSC->mStateFont.mActiveFonts[ct] == this) {
-            mRSC->mStateFont.mActiveFonts.removeAt(ct);
-            break;
+    auto &activeFonts = mRSC->mStateFont.mActiveFonts;
+
+    for (auto font = activeFonts.begin(), end = activeFonts.end(); font != end;
+         font++) {
+
+        if (this == *font) {
+            activeFonts.erase(font);
+            return;
         }
     }
 }
 
 void Font::invalidateTextureCache() {
     for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
-        mCachedGlyphs.valueAt(i)->mIsValid = false;
+        mCachedGlyphs[i]->mIsValid = false;
     }
 }
 
@@ -224,7 +228,7 @@
 
 Font::CachedGlyphInfo* Font::getCachedUTFChar(int32_t utfChar) {
 
-    CachedGlyphInfo *cachedGlyph = mCachedGlyphs.valueFor((uint32_t)utfChar);
+    CachedGlyphInfo *cachedGlyph = mCachedGlyphs[(uint32_t)utfChar];
     if (cachedGlyph == NULL) {
         cachedGlyph = cacheGlyph((uint32_t)utfChar);
     }
@@ -283,7 +287,7 @@
 
 Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) {
     CachedGlyphInfo *newGlyph = new CachedGlyphInfo();
-    mCachedGlyphs.add(glyph, newGlyph);
+    mCachedGlyphs[glyph] = newGlyph;
 #ifndef ANDROID_RS_SERIALIZE
     newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph);
     newGlyph->mIsValid = false;
@@ -296,11 +300,14 @@
 Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi,
                     const void *data, uint32_t dataLen) {
     rsc->mStateFont.checkInit();
-    Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts;
+    std::vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts;
 
     for (uint32_t i = 0; i < activeFonts.size(); i ++) {
         Font *ithFont = activeFonts[i];
-        if (ithFont->mFontName == name && ithFont->mFontSize == fontSize && ithFont->mDpi == dpi) {
+        if (ithFont->mFontName == name &&
+            ithFont->mFontSize == fontSize &&
+            ithFont->mDpi == dpi) {
+
             return ithFont;
         }
     }
@@ -308,7 +315,7 @@
     Font *newFont = new Font(rsc);
     bool isInitialized = newFont->init(name, fontSize, dpi, data, dataLen);
     if (isInitialized) {
-        activeFonts.push(newFont);
+        activeFonts.push_back(newFont);
         rsc->mStateFont.precacheLatin(newFont);
         return newFont;
     }
@@ -325,7 +332,7 @@
 #endif
 
     for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
-        CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i);
+        CachedGlyphInfo *glyph = mCachedGlyphs[i];
         delete glyph;
     }
 }
@@ -551,29 +558,39 @@
     mCacheHeight = 256;
     mCacheWidth = 1024;
     ObjectBaseRef<Type> texType = Type::getTypeRef(mRSC, alphaElem.get(),
-                                                   mCacheWidth, mCacheHeight, 0, false, false, 0);
+                                                   mCacheWidth, mCacheHeight,
+                                                   0, false, false, 0);
+
     mCacheBuffer = new uint8_t[mCacheWidth * mCacheHeight];
 
 
-    Allocation *cacheAlloc = Allocation::createAllocation(mRSC, texType.get(),
-                                RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE);
+    Allocation *cacheAlloc =
+        Allocation::createAllocation(mRSC, texType.get(),
+                                     RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE);
     mTextTexture.set(cacheAlloc);
 
     // Split up our cache texture into lines of certain widths
     int32_t nextLine = 0;
-    mCacheLines.push(new CacheTextureLine(16, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(40, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(texType->getDimY() - nextLine, texType->getDimX(), nextLine, 0));
+    mCacheLines.push_back(new CacheTextureLine(16, texType->getDimX(),
+                          nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(24, texType->getDimX(),
+                          nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(24, texType->getDimX(),
+                          nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(32, texType->getDimX(),
+                          nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(32, texType->getDimX(),
+                          nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(40, texType->getDimX(),
+                          nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(texType->getDimY() - nextLine,
+                          texType->getDimX(), nextLine, 0));
 }
 
 // Avoid having to reallocate memory and render quad by quad
diff --git a/rsFont.h b/rsFont.h
index 7bac508..71e6fb4 100644
--- a/rsFont.h
+++ b/rsFont.h
@@ -17,9 +17,10 @@
 #ifndef ANDROID_RS_FONT_H
 #define ANDROID_RS_FONT_H
 
+#include <map>
+#include <vector>
+
 #include "rsStream.h"
-#include <utils/Vector.h>
-#include <utils/KeyedVector.h>
 
 struct FT_LibraryRec_;
 struct FT_FaceRec_;
@@ -124,7 +125,7 @@
     bool mInitialized;
     bool mHasKerning;
 
-    DefaultKeyedVector<uint32_t, CachedGlyphInfo* > mCachedGlyphs;
+    std::map<uint32_t, CachedGlyphInfo* > mCachedGlyphs;
     CachedGlyphInfo* getCachedUTFChar(int32_t utfChar);
 
     CachedGlyphInfo *cacheGlyph(uint32_t glyph);
@@ -178,7 +179,7 @@
         bool fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY);
     };
 
-    Vector<CacheTextureLine*> mCacheLines;
+    std::vector<CacheTextureLine*> mCacheLines;
     uint32_t getRemainingCacheCapacity();
 
     void precacheLatin(Font *font);
@@ -203,7 +204,7 @@
     FT_LibraryRec_ *mLibrary;
     FT_LibraryRec_ *getLib();
 #endif //ANDROID_RS_SERIALIZE
-    Vector<Font*> mActiveFonts;
+    std::vector<Font*> mActiveFonts;
 
     // Render state for the font
     ObjectBaseRef<Allocation> mFontShaderFConstant;
diff --git a/rsGrallocConsumer.h b/rsGrallocConsumer.h
index 9e4fc58..b134862 100644
--- a/rsGrallocConsumer.h
+++ b/rsGrallocConsumer.h
@@ -17,12 +17,13 @@
 #ifndef ANDROID_RS_GRALLOC_CONSUMER_H
 #define ANDROID_RS_GRALLOC_CONSUMER_H
 
+#include <vector>
+
 #include <gui/ConsumerBase.h>
 
 #include <ui/GraphicBuffer.h>
 
 #include <utils/String8.h>
-#include <utils/Vector.h>
 #include <utils/threads.h>
 
 
@@ -75,4 +76,3 @@
 } // namespace android
 
 #endif // ANDROID_RS_GRALLOC_CONSUMER_H
-
diff --git a/rsProgramFragment.h b/rsProgramFragment.h
index e7456b9..1357bfc 100644
--- a/rsProgramFragment.h
+++ b/rsProgramFragment.h
@@ -55,7 +55,7 @@
     void deinit(Context *rsc);
 
     ObjectBaseRef<ProgramFragment> mDefault;
-    Vector<ProgramFragment *> mPrograms;
+    std::vector<ProgramFragment *> mPrograms;
 
     ObjectBaseRef<ProgramFragment> mLast;
 };
@@ -63,7 +63,3 @@
 }
 }
 #endif
-
-
-
-
diff --git a/rsProgramRaster.cpp b/rsProgramRaster.cpp
index 4f27f2e..d2d0602 100644
--- a/rsProgramRaster.cpp
+++ b/rsProgramRaster.cpp
@@ -31,10 +31,14 @@
 }
 
 void ProgramRaster::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateRaster.mRasterPrograms.size(); ct++) {
-        if (mRSC->mStateRaster.mRasterPrograms[ct] == this) {
-            mRSC->mStateRaster.mRasterPrograms.removeAt(ct);
-            break;
+    auto &rasters = mRSC->mStateRaster.mRasterPrograms;
+
+    for (auto prIter = rasters.begin(), endIter = rasters.end();
+         prIter != endIter; prIter++) {
+
+        if (this == *prIter) {
+            rasters.erase(prIter);
+            return;
         }
     }
 }
@@ -94,7 +98,7 @@
     returnRef.set(pr);
 
     ObjectBase::asyncLock();
-    rsc->mStateRaster.mRasterPrograms.push(pr);
+    rsc->mStateRaster.mRasterPrograms.push_back(pr);
     ObjectBase::asyncUnlock();
 
     return returnRef;
@@ -111,4 +115,3 @@
 
 }
 }
-
diff --git a/rsProgramRaster.h b/rsProgramRaster.h
index e9a524b..207d74c 100644
--- a/rsProgramRaster.h
+++ b/rsProgramRaster.h
@@ -75,14 +75,10 @@
     ObjectBaseRef<ProgramRaster> mLast;
 
     // Cache of all existing raster programs.
-    Vector<ProgramRaster *> mRasterPrograms;
+    std::vector<ProgramRaster *> mRasterPrograms;
 };
 
 
 }
 }
 #endif
-
-
-
-
diff --git a/rsProgramStore.cpp b/rsProgramStore.cpp
index 83c1f2c..b2d527e 100644
--- a/rsProgramStore.cpp
+++ b/rsProgramStore.cpp
@@ -42,10 +42,14 @@
 }
 
 void ProgramStore::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateFragmentStore.mStorePrograms.size(); ct++) {
-        if (mRSC->mStateFragmentStore.mStorePrograms[ct] == this) {
-            mRSC->mStateFragmentStore.mStorePrograms.removeAt(ct);
-            break;
+    auto &stores = mRSC->mStateFragmentStore.mStorePrograms;
+
+    for (auto psIter = stores.begin(), endIter = stores.end();
+         psIter != endIter; psIter++) {
+
+        if (this == *psIter) {
+            stores.erase(psIter);
+            return;
         }
     }
 }
@@ -118,7 +122,7 @@
     pfs->init();
 
     ObjectBase::asyncLock();
-    rsc->mStateFragmentStore.mStorePrograms.push(pfs);
+    rsc->mStateFragmentStore.mStorePrograms.push_back(pfs);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsProgramStore.h b/rsProgramStore.h
index 9a7f7f1..06824fe 100644
--- a/rsProgramStore.h
+++ b/rsProgramStore.h
@@ -92,12 +92,9 @@
     ObjectBaseRef<ProgramStore> mLast;
 
     // Cache of all existing store programs.
-    Vector<ProgramStore *> mStorePrograms;
+    std::vector<ProgramStore *> mStorePrograms;
 };
 
 }
 }
 #endif
-
-
-
diff --git a/rsSampler.cpp b/rsSampler.cpp
index 0cf0b55..0ea9729 100644
--- a/rsSampler.cpp
+++ b/rsSampler.cpp
@@ -49,10 +49,14 @@
 }
 
 void Sampler::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateSampler.mAllSamplers.size(); ct++) {
-        if (mRSC->mStateSampler.mAllSamplers[ct] == this) {
-            mRSC->mStateSampler.mAllSamplers.removeAt(ct);
-            break;
+    auto &samplers = mRSC->mStateSampler.mAllSamplers;
+
+    for (auto sampleIter = samplers.begin(), endIter = samplers.end();
+         sampleIter != endIter; sampleIter++) {
+
+        if (this == *sampleIter) {
+            samplers.erase(sampleIter);
+            return;
         }
     }
 }
@@ -113,7 +117,7 @@
 #endif
 
     ObjectBase::asyncLock();
-    rsc->mStateSampler.mAllSamplers.push(s);
+    rsc->mStateSampler.mAllSamplers.push_back(s);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsSampler.h b/rsSampler.h
index 2fdf707..3f5855f 100644
--- a/rsSampler.h
+++ b/rsSampler.h
@@ -96,12 +96,9 @@
         }
     }
     // Cache of all existing raster programs.
-    Vector<Sampler *> mAllSamplers;
+    std::vector<Sampler *> mAllSamplers;
 };
 
 }
 }
 #endif //ANDROID_RS_SAMPLER_H
-
-
-
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 892807b..2958e84 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <string>
+
 #include "rsContext.h"
 #include "rsScriptC.h"
 
@@ -165,15 +167,14 @@
     // Trace this function call.
     // To avoid overhead we only build the string if tracing is actually
     // enabled.
-    String8 *AString = NULL;
-    const char *String = "";
+    std::string *traceString = NULL;
+    const char  *stringData  = "";
     if (ATRACE_ENABLED()) {
-        AString = new String8("runForEach_");
-        AString->append(mHal.info.exportedForeachFuncList[slot].first);
-        String = AString->string();
+        traceString = new std::string("runForEach_");
+        traceString->append(mHal.info.exportedForeachFuncList[slot].first);
+        stringData = traceString->c_str();
     }
-    ATRACE_NAME(String);
-    (void)String;
+    ATRACE_NAME(stringData);
 
     Context::PushState ps(rsc);
 
@@ -193,8 +194,8 @@
                       "Driver support for multi-input not present");
     }
 
-    if (AString) {
-        delete AString;
+    if (traceString) {
+        delete traceString;
     }
 }
 
diff --git a/rsScriptGroup.cpp b/rsScriptGroup.cpp
index a03cb78..f41c65d 100644
--- a/rsScriptGroup.cpp
+++ b/rsScriptGroup.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <algorithm>
+
 #include "rsContext.h"
 #include <time.h>
 
@@ -28,8 +30,8 @@
         mRSC->mHal.funcs.scriptgroup.destroy(mRSC, this);
     }
 
-    for (size_t ct=0; ct < mLinks.size(); ct++) {
-        delete mLinks[ct];
+    for (auto link : mLinks) {
+        delete link;
     }
 }
 
@@ -44,148 +46,116 @@
 }
 
 ScriptGroup::Node * ScriptGroup::findNode(Script *s) const {
-    //ALOGE("find %p   %i", s, (int)mNodes.size());
-    for (size_t ct=0; ct < mNodes.size(); ct++) {
-        Node *n = mNodes[ct];
-        for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) {
-            if (n->mKernels[ct2]->mScript == s) {
-                return n;
+    for (auto node : mNodes) {
+        for (auto kernelRef : node->mKernels) {
+            if (kernelRef->mScript == s) {
+                return node;
             }
         }
     }
+
     return NULL;
 }
 
-bool ScriptGroup::calcOrderRecurse(Node *n, int depth) {
-    n->mSeen = true;
-    if (n->mOrder < depth) {
-        n->mOrder = depth;
+bool ScriptGroup::calcOrderRecurse(Node *node0, int depth) {
+    node0->mSeen = true;
+    if (node0->mOrder < depth) {
+        node0->mOrder = depth;
     }
     bool ret = true;
-    for (size_t ct=0; ct < n->mOutputs.size(); ct++) {
-        const Link *l = n->mOutputs[ct];
-        Node *nt = NULL;
-        if (l->mDstField.get()) {
-            nt = findNode(l->mDstField->mScript);
+
+    for (auto link : node0->mOutputs) {
+        Node *node1 = NULL;
+        if (link->mDstField.get()) {
+            node1 = findNode(link->mDstField->mScript);
         } else {
-            nt = findNode(l->mDstKernel->mScript);
+            node1 = findNode(link->mDstKernel->mScript);
         }
-        if (nt->mSeen) {
+        if (node1->mSeen) {
             return false;
         }
-        ret &= calcOrderRecurse(nt, n->mOrder + 1);
+        ret &= calcOrderRecurse(node1, node0->mOrder + 1);
     }
+
     return ret;
 }
 
-#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
-static int CompareNodeForSort(ScriptGroup::Node *const* lhs,
-                              ScriptGroup::Node *const* rhs) {
-    if (lhs[0]->mOrder > rhs[0]->mOrder) {
-        return 1;
-    }
-    return 0;
-}
-#else
-class NodeCompare {
-public:
-    bool operator() (const ScriptGroup::Node* lhs,
-                     const ScriptGroup::Node* rhs) {
-        if (lhs->mOrder > rhs->mOrder) {
-            return true;
-        }
-        return false;
-    }
-};
-#endif
-
 bool ScriptGroup::calcOrder() {
     // Make nodes
-    for (size_t ct=0; ct < mKernels.size(); ct++) {
-        const ScriptKernelID *k = mKernels[ct].get();
-        //ALOGE(" kernel %i, %p  s=%p", (int)ct, k, mKernels[ct]->mScript);
-        Node *n = findNode(k->mScript);
-        //ALOGE("    n = %p", n);
-        if (n == NULL) {
-            n = new Node(k->mScript);
-            mNodes.add(n);
+
+    for (auto kernelRef : mKernels) {
+        const ScriptKernelID *kernel = kernelRef.get();
+        Node *node = findNode(kernel->mScript);
+        if (node == NULL) {
+            node = new Node(kernel->mScript);
+            mNodes.push_back(node);
         }
-        n->mKernels.add(k);
+        node->mKernels.push_back(kernel);
     }
 
     // add links
-    //ALOGE("link count %i", (int)mLinks.size());
-    for (size_t ct=0; ct < mLinks.size(); ct++) {
-        Link *l = mLinks[ct];
-        //ALOGE("link  %i %p", (int)ct, l);
-        Node *n = findNode(l->mSource->mScript);
-        //ALOGE("link n %p", n);
-        n->mOutputs.add(l);
+    for (auto link : mLinks) {
+        Node *node = findNode(link->mSource->mScript);
+        node->mOutputs.push_back(link);
 
-        if (l->mDstKernel.get()) {
-            //ALOGE("l->mDstKernel.get() %p", l->mDstKernel.get());
-            n = findNode(l->mDstKernel->mScript);
-            //ALOGE("  n1 %p", n);
-            n->mInputs.add(l);
+        if (link->mDstKernel.get()) {
+            node = findNode(link->mDstKernel->mScript);
+            node->mInputs.push_back(link);
         } else {
-            n = findNode(l->mDstField->mScript);
-            //ALOGE("  n2 %p", n);
-            n->mInputs.add(l);
+            node = findNode(link->mDstField->mScript);
+            node->mInputs.push_back(link);
         }
     }
 
-    //ALOGE("node count %i", (int)mNodes.size());
     // Order nodes
     bool ret = true;
-    for (size_t ct=0; ct < mNodes.size(); ct++) {
-        Node *n = mNodes[ct];
-        if (n->mInputs.size() == 0) {
-            for (size_t ct2=0; ct2 < mNodes.size(); ct2++) {
-                mNodes[ct2]->mSeen = false;
+    for (auto n0 : mNodes) {
+        if (n0->mInputs.size() == 0) {
+            for (auto n1 : mNodes) {
+                n1->mSeen = false;
             }
-            ret &= calcOrderRecurse(n, 0);
+            ret &= calcOrderRecurse(n0, 1);
         }
     }
 
-    for (size_t ct=0; ct < mKernels.size(); ct++) {
-        const ScriptKernelID *k = mKernels[ct].get();
-        const Node *n = findNode(k->mScript);
+    for (auto kernelRef : mKernels) {
+        const ScriptKernelID *kernel = kernelRef.get();
+        const Node *node = findNode(kernel->mScript);
 
-        if (k->mHasKernelOutput) {
+        if (kernel->mHasKernelOutput) {
             bool found = false;
-            for (size_t ct2=0; ct2 < n->mOutputs.size(); ct2++) {
-                if (n->mOutputs[ct2]->mSource.get() == k) {
+            for (auto output : node->mOutputs) {
+                if (output->mSource.get() == kernel) {
                     found = true;
                     break;
                 }
             }
+
             if (!found) {
-                //ALOGE("add io out %p", k);
-                mOutputs.add(new IO(k));
+                mOutputs.push_back(new IO(kernel));
             }
         }
 
-        if (k->mHasKernelInput) {
+        if (kernel->mHasKernelInput) {
             bool found = false;
-            for (size_t ct2=0; ct2 < n->mInputs.size(); ct2++) {
-                if (n->mInputs[ct2]->mDstKernel.get() == k) {
+            for (auto input : node->mInputs) {
+                if (input->mDstKernel.get() == kernel) {
                     found = true;
                     break;
                 }
             }
             if (!found) {
-                //ALOGE("add io in %p", k);
-                mInputs.add(new IO(k));
+                mInputs.push_back(new IO(kernel));
             }
         }
     }
 
     // sort
-#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
-    mNodes.sort(&CompareNodeForSort);
-#else
-    std::sort(mNodes.begin(), mNodes.end(), NodeCompare());
-#endif
+    std::stable_sort(mNodes.begin(), mNodes.end(),
+                     [](const ScriptGroup::Node* lhs,
+                        const ScriptGroup::Node* rhs) {
+        return lhs->mOrder < rhs->mOrder;
+    });
 
     return ret;
 }
@@ -209,7 +179,7 @@
 
     sg->mKernels.reserve(kernelCount);
     for (size_t ct=0; ct < kernelCount; ct++) {
-        sg->mKernels.add(kernels[ct]);
+        sg->mKernels.push_back(kernels[ct]);
     }
 
     sg->mLinks.reserve(linkCount);
@@ -219,7 +189,7 @@
         l->mSource = src[ct];
         l->mDstField = dstF[ct];
         l->mDstKernel = dstK[ct];
-        sg->mLinks.add(l);
+        sg->mLinks.push_back(l);
     }
 
     sg->calcOrder();
@@ -254,9 +224,9 @@
 }
 
 void ScriptGroup::setInput(Context *rsc, ScriptKernelID *kid, Allocation *a) {
-    for (size_t ct=0; ct < mInputs.size(); ct++) {
-        if (mInputs[ct]->mKernel == kid) {
-            mInputs[ct]->mAlloc = a;
+    for (auto input : mInputs) {
+        if (input->mKernel == kid) {
+            input->mAlloc = a;
 
             if (rsc->mHal.funcs.scriptgroup.setInput) {
                 rsc->mHal.funcs.scriptgroup.setInput(rsc, this, kid, a);
@@ -268,9 +238,9 @@
 }
 
 void ScriptGroup::setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a) {
-    for (size_t ct=0; ct < mOutputs.size(); ct++) {
-        if (mOutputs[ct]->mKernel == kid) {
-            mOutputs[ct]->mAlloc = a;
+    for (auto output : mOutputs) {
+        if (output->mKernel == kid) {
+            output->mAlloc = a;
 
             if (rsc->mHal.funcs.scriptgroup.setOutput) {
                 rsc->mHal.funcs.scriptgroup.setOutput(rsc, this, kid, a);
@@ -311,52 +281,45 @@
         return;
     }
 
-    for (size_t ct=0; ct < mNodes.size(); ct++) {
-        Node *n = mNodes[ct];
-        //ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size());
-
-        for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) {
-            const ScriptKernelID *k = n->mKernels[ct2];
-            Allocation *ain = NULL;
+    for (auto node : mNodes) {
+        for (auto kernel : node->mKernels) {
+            Allocation *ain  = NULL;
             Allocation *aout = NULL;
 
-            for (size_t ct3=0; ct3 < n->mInputs.size(); ct3++) {
-                if (n->mInputs[ct3]->mDstKernel.get() == k) {
-                    ain = n->mInputs[ct3]->mAlloc.get();
-                    //ALOGE(" link in %p", ain);
-                }
-            }
-            for (size_t ct3=0; ct3 < mInputs.size(); ct3++) {
-                if (mInputs[ct3]->mKernel == k) {
-                    ain = mInputs[ct3]->mAlloc.get();
-                    //ALOGE(" io in %p", ain);
+            for (auto nodeInput : node->mInputs) {
+                if (nodeInput->mDstKernel.get() == kernel) {
+                    ain = nodeInput->mAlloc.get();
                 }
             }
 
-            for (size_t ct3=0; ct3 < n->mOutputs.size(); ct3++) {
-                if (n->mOutputs[ct3]->mSource.get() == k) {
-                    aout = n->mOutputs[ct3]->mAlloc.get();
-                    //ALOGE(" link out %p", aout);
+            for (auto sgInput : mInputs) {
+                if (sgInput->mKernel == kernel) {
+                    ain = sgInput->mAlloc.get();
                 }
             }
-            for (size_t ct3=0; ct3 < mOutputs.size(); ct3++) {
-                if (mOutputs[ct3]->mKernel == k) {
-                    aout = mOutputs[ct3]->mAlloc.get();
-                    //ALOGE(" io out %p", aout);
+
+            for (auto nodeOutput : node->mOutputs) {
+                if (nodeOutput->mDstKernel.get() == kernel) {
+                    aout = nodeOutput->mAlloc.get();
+                }
+            }
+
+            for (auto sgOutput : mOutputs) {
+                if (sgOutput->mKernel == kernel) {
+                    aout = sgOutput->mAlloc.get();
                 }
             }
 
             if (ain == NULL) {
-                n->mScript->runForEach(rsc, k->mSlot, NULL, 0, aout, NULL, 0);
-
+                node->mScript->runForEach(rsc, kernel->mSlot, NULL, 0, aout,
+                                          NULL, 0);
             } else {
                 const Allocation *ains[1] = {ain};
-                n->mScript->runForEach(rsc, k->mSlot, ains,
-                                       sizeof(ains) / sizeof(RsAllocation),
-                                       aout, NULL, 0);
+                node->mScript->runForEach(rsc, kernel->mSlot, ains,
+                                          sizeof(ains) / sizeof(RsAllocation),
+                                          aout, NULL, 0);
             }
         }
-
     }
 
 }
@@ -397,20 +360,17 @@
 
 void rsi_ScriptGroupSetInput(Context *rsc, RsScriptGroup sg, RsScriptKernelID kid,
         RsAllocation alloc) {
-    //ALOGE("rsi_ScriptGroupSetInput");
     ScriptGroup *s = (ScriptGroup *)sg;
     s->setInput(rsc, (ScriptKernelID *)kid, (Allocation *)alloc);
 }
 
 void rsi_ScriptGroupSetOutput(Context *rsc, RsScriptGroup sg, RsScriptKernelID kid,
         RsAllocation alloc) {
-    //ALOGE("rsi_ScriptGroupSetOutput");
     ScriptGroup *s = (ScriptGroup *)sg;
     s->setOutput(rsc, (ScriptKernelID *)kid, (Allocation *)alloc);
 }
 
 void rsi_ScriptGroupExecute(Context *rsc, RsScriptGroup sg) {
-    //ALOGE("rsi_ScriptGroupExecute");
     ScriptGroup *s = (ScriptGroup *)sg;
     s->execute(rsc);
 }
diff --git a/rsScriptGroup.h b/rsScriptGroup.h
index af98b50..974e3ba 100644
--- a/rsScriptGroup.h
+++ b/rsScriptGroup.h
@@ -32,7 +32,7 @@
 
 class ScriptGroup : public ObjectBase {
 public:
-    Vector<ObjectBaseRef<ScriptKernelID> > mKernels;
+    std::vector<ObjectBaseRef<ScriptKernelID> > mKernels;
 
     class Link {
     public:
@@ -49,9 +49,9 @@
     public:
         Node(Script *);
 
-        Vector<const ScriptKernelID *> mKernels;
-        Vector<Link *> mOutputs;
-        Vector<Link *> mInputs;
+        std::vector<const ScriptKernelID *> mKernels;
+        std::vector<Link *> mOutputs;
+        std::vector<Link *> mInputs;
         bool mSeen;
         int mOrder;
         Script *mScript;
@@ -65,10 +65,10 @@
         ObjectBaseRef<Allocation> mAlloc;
     };
 
-    Vector<Link *> mLinks;
-    Vector<Node *> mNodes;
-    Vector<IO *> mInputs;
-    Vector<IO *> mOutputs;
+    std::vector<Link *> mLinks;
+    std::vector<Node *> mNodes;
+    std::vector<IO *> mInputs;
+    std::vector<IO *> mOutputs;
 
     struct Hal {
         void * drv;
@@ -115,4 +115,3 @@
 }
 }
 #endif
-
diff --git a/rsType.cpp b/rsType.cpp
index d1a84ea..ba57617 100644
--- a/rsType.cpp
+++ b/rsType.cpp
@@ -33,10 +33,14 @@
 }
 
 void Type::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateType.mTypes.size(); ct++) {
-        if (mRSC->mStateType.mTypes[ct] == this) {
-            mRSC->mStateType.mTypes.removeAt(ct);
-            break;
+    auto &types = mRSC->mStateType.mTypes;
+
+    for (auto typeIter = types.begin(), endIter = types.end();
+         typeIter != endIter; typeIter++) {
+
+        if (this == *typeIter) {
+            types.erase(typeIter);
+            return;
         }
     }
 }
@@ -258,7 +262,7 @@
     nt->compute();
 
     ObjectBase::asyncLock();
-    stc->mTypes.push(nt);
+    stc->mTypes.push_back(nt);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsType.h b/rsType.h
index e44e270..86d6ece 100644
--- a/rsType.h
+++ b/rsType.h
@@ -146,7 +146,7 @@
     ~TypeState();
 
     // Cache of all existing types.
-    Vector<Type *> mTypes;
+    std::vector<Type *> mTypes;
 };