Reformat and remove STL reference from header

b/19148482

Reformmated according to Android C++ style guidelines.
Removed STL references in headers.

Change-Id: I6d82b8fe5ac868067b6d9ebe797125feb97e5641
diff --git a/rsClosure.cpp b/rsClosure.cpp
index 7aa0acb..ece92d5 100644
--- a/rsClosure.cpp
+++ b/rsClosure.cpp
@@ -16,15 +16,15 @@
                             RsClosure* depClosures, size_t depClosures_length,
                             RsScriptFieldID* depFieldIDs,
                             size_t depFieldIDs_length) {
-  rsAssert(fieldIDs_length == values_length && values_length == sizes_length &&
-           sizes_length == depClosures_length &&
-           depClosures_length == depFieldIDs_length);
+    rsAssert(fieldIDs_length == values_length && values_length == sizes_length &&
+             sizes_length == depClosures_length &&
+             depClosures_length == depFieldIDs_length);
 
-  return (RsClosure)(new Closure(
-      context, (const ScriptKernelID*)kernelID, (Allocation*)returnValue,
-      fieldIDs_length, (const ScriptFieldID**)fieldIDs, (const void**)values,
-      sizes, (const Closure**)depClosures,
-      (const ScriptFieldID**)depFieldIDs));
+    return (RsClosure)(new Closure(
+        context, (const ScriptKernelID*)kernelID, (Allocation*)returnValue,
+        fieldIDs_length, (const ScriptFieldID**)fieldIDs, (const void**)values,
+        sizes, (const Closure**)depClosures,
+        (const ScriptFieldID**)depFieldIDs));
 }
 
 RsClosure rsi_InvokeClosureCreate(Context* context, RsScriptInvokeID invokeID,
@@ -39,9 +39,11 @@
         sizes));
 }
 
+#if 0
 void rsi_ClosureEval(Context* rsc, RsClosure closure) {
     ((Closure*)closure)->eval();
 }
+#endif
 
 void rsi_ClosureSetArg(Context* rsc, RsClosure closure, uint32_t index,
                        uintptr_t value, size_t size) {
@@ -67,47 +69,59 @@
     ObjectBase(context), mContext(context), mKernelID((ScriptKernelID*)kernelID),
     mInvokeID(nullptr), mReturnValue(returnValue), mParams(nullptr),
     mParamLength(0) {
-  size_t i;
+    size_t i;
 
-  for (i = 0; i < (size_t)numValues && fieldIDs[i] == nullptr; i++);
+    for (i = 0; i < (size_t)numValues && fieldIDs[i] == nullptr; i++);
 
-  vector<const void*> args(values, values + i);
-  mArgs.swap(args);
+    mNumArg = i;
+    mArgs = new const void*[mNumArg];
+    memcpy(mArgs, values, sizeof(const void*) * mNumArg);
 
-  for (; i < (size_t)numValues; i++) {
-    mGlobals[fieldIDs[i]] = std::make_pair(values[i], sizes[i]);
-  }
-
-  mDependences.insert(depClosures, depClosures + numValues);
-
-  for (i = 0; i < mArgs.size(); i++) {
-    const Closure* dep = depClosures[i];
-    if (dep != nullptr) {
-      auto mapping = mArgDeps[dep];
-      if (mapping == nullptr) {
-        mapping = new map<int, const ObjectBaseRef<ScriptFieldID>*>();
-        mArgDeps[dep] = mapping;
-      }
-      (*mapping)[i] = new ObjectBaseRef<ScriptFieldID>(
-          const_cast<ScriptFieldID*>(depFieldIDs[i]));
+    for (; i < (size_t)numValues; i++) {
+        rsAssert(fieldIDs[i] != nullptr);
+        mGlobals[fieldIDs[i]] = make_pair(values[i], sizes[i]);
+        ALOGV("Creating closure %p, binding field %p (Script %p, slot: %d)",
+              this, fieldIDs[i], fieldIDs[i]->mScript, fieldIDs[i]->mSlot);
     }
-  }
 
-  for (; i < (size_t)numValues; i++) {
-    const Closure* dep = depClosures[i];
-    if (dep != nullptr) {
-      auto mapping = mGlobalDeps[dep];
-      if (mapping == nullptr) {
-        mapping = new map<const ObjectBaseRef<ScriptFieldID>*,
-            const ObjectBaseRef<ScriptFieldID>*>();
-        mGlobalDeps[dep] = mapping;
-      }
-      (*mapping)[new ObjectBaseRef<ScriptFieldID>(
-          const_cast<ScriptFieldID*>(fieldIDs[i]))] =
-          new ObjectBaseRef<ScriptFieldID>(
-              const_cast<ScriptFieldID*>(depFieldIDs[i]));
+    size_t j = mNumArg;
+    for (const auto& p : mGlobals) {
+        rsAssert(p.first == fieldIDs[j]);
+        rsAssert(p.second.first == values[j]);
+        rsAssert(p.second.second == sizes[j]);
+        j++;
     }
-  }
+
+    // mDependences.insert(depClosures, depClosures + numValues);
+
+    for (i = 0; i < mNumArg; i++) {
+        const Closure* dep = depClosures[i];
+        if (dep != nullptr) {
+            auto mapping = mArgDeps[dep];
+            if (mapping == nullptr) {
+                mapping = new Map<int, const ObjectBaseRef<ScriptFieldID>*>();
+                mArgDeps[dep] = mapping;
+            }
+            (*mapping)[i] = new ObjectBaseRef<ScriptFieldID>(
+                const_cast<ScriptFieldID*>(depFieldIDs[i]));
+        }
+    }
+
+    for (; i < (size_t)numValues; i++) {
+        const Closure* dep = depClosures[i];
+        if (dep != nullptr) {
+            auto mapping = mGlobalDeps[dep];
+            if (mapping == nullptr) {
+                mapping = new Map<const ObjectBaseRef<ScriptFieldID>*,
+                                  const ObjectBaseRef<ScriptFieldID>*>();
+                mGlobalDeps[dep] = mapping;
+            }
+            (*mapping)[new ObjectBaseRef<ScriptFieldID>(
+                const_cast<ScriptFieldID*>(fieldIDs[i]))] =
+                    new ObjectBaseRef<ScriptFieldID>(
+                        const_cast<ScriptFieldID*>(depFieldIDs[i]));
+        }
+    }
 }
 
 Closure::Closure(Context* context, const ScriptInvokeID* invokeID,
@@ -117,7 +131,7 @@
     ObjectBase(context), mContext(context), mKernelID(nullptr), mInvokeID(invokeID),
     mReturnValue(nullptr), mParams(params), mParamLength(paramLength) {
     for (size_t i = 0; i < numValues; i++) {
-        mGlobals[fieldIDs[i]] = std::make_pair(values[i], sizes[i]);
+        mGlobals[fieldIDs[i]] = make_pair(values[i], sizes[i]);
     }
 }
 
@@ -138,24 +152,8 @@
         }
         delete p.second;
     }
-}
 
-void Closure::eval() {
-    Script *s = mKernelID->mScript;
-
-    for (const auto& p : mGlobals) {
-        const void* value = p.second.first;
-        int size = p.second.second;
-        // We use -1 size to indicate an ObjectBase rather than a primitive type
-        if (size < 0) {
-            s->setVarObj(p.first->mSlot, (ObjectBase*)value);
-        } else {
-            s->setVar(p.first->mSlot, (const void*)&value, size);
-        }
-    }
-
-    s->runForEach(mContext, mKernelID->mSlot, (const Allocation **)(&mArgs[0]),
-                  mArgs.size(), mReturnValue, nullptr, 0, nullptr);
+    delete[] mArgs;
 }
 
 void Closure::setArg(const uint32_t index, const void* value, const size_t size) {
@@ -164,7 +162,7 @@
 
 void Closure::setGlobal(const ScriptFieldID* fieldID, const void* value,
                         const size_t size) {
-    mGlobals[fieldID] = std::make_pair(value, size);
+    mGlobals[fieldID] = make_pair(value, size);
 }
 
 }  // namespace renderscript