Fix clang-tidy performance warnings.

* Use const reference type for read-only parameters.
Bug: 30407689
Test: build with WITH_TIDY=1

Change-Id: I7c19a10f0ae0b4784851bedbcaf1c4565c6616d1
diff --git a/cpp/Allocation.cpp b/cpp/Allocation.cpp
index 7d3a541..3f29073 100644
--- a/cpp/Allocation.cpp
+++ b/cpp/Allocation.cpp
@@ -25,7 +25,7 @@
     return getID();
 }
 
-void Allocation::updateCacheInfo(sp<const Type> t) {
+void Allocation::updateCacheInfo(const sp<const Type>& t) {
     mCurrentDimX = t->getX();
     mCurrentDimY = t->getY();
     mCurrentDimZ = t->getZ();
@@ -261,7 +261,7 @@
     }
 }
 
-void Allocation::copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data,
+void Allocation::copy1DRangeFrom(uint32_t off, size_t count, const sp<const Allocation>& data,
                                  uint32_t dataOff) {
 
     tryDispatch(mRS, RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), off, 0,
@@ -310,7 +310,7 @@
 }
 
 void Allocation::copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
-                                 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff) {
+                                 const sp<const Allocation>& data, uint32_t dataXoff, uint32_t dataYoff) {
     validate2DRange(xoff, yoff, w, h);
     tryDispatch(mRS, RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), xoff, yoff,
                                                          mSelectedLOD, mSelectedFace,
@@ -394,7 +394,7 @@
 }
 
 void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d,
-                                 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff) {
+                                 const sp<const Allocation>& data, uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff) {
     validate3DRange(xoff, yoff, zoff, w, h, d);
     tryDispatch(mRS, RS::dispatch->AllocationCopy3DRange(mRS->getContext(), getIDSafe(), xoff, yoff, zoff,
                                                          mSelectedLOD, w, h, d, data->getIDSafe(),
@@ -421,7 +421,7 @@
     }
 }
 
-sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
+sp<Allocation> Allocation::createTyped(const sp<RS>& rs, const sp<const Type>& type,
                                     RsAllocationMipmapControl mipmaps, uint32_t usage) {
     void *id = 0;
     if (rs->getError() == RS_SUCCESS) {
@@ -434,7 +434,7 @@
     return new Allocation(id, rs, type, usage);
 }
 
-sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
+sp<Allocation> Allocation::createTyped(const sp<RS>& rs, const sp<const Type>& type,
                                     RsAllocationMipmapControl mipmaps, uint32_t usage,
                                     void *pointer) {
     void *id = 0;
@@ -449,12 +449,12 @@
     return new Allocation(id, rs, type, usage);
 }
 
-sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type,
+sp<Allocation> Allocation::createTyped(const sp<RS>& rs, const sp<const Type>& type,
                                     uint32_t usage) {
     return createTyped(rs, type, RS_ALLOCATION_MIPMAP_NONE, usage);
 }
 
-sp<Allocation> Allocation::createSized(sp<RS> rs, sp<const Element> e,
+sp<Allocation> Allocation::createSized(const sp<RS>& rs, const sp<const Element>& e,
                                     size_t count, uint32_t usage) {
     Type::Builder b(rs, e);
     b.setX(count);
@@ -463,7 +463,7 @@
     return createTyped(rs, t, usage);
 }
 
-sp<Allocation> Allocation::createSized2D(sp<RS> rs, sp<const Element> e,
+sp<Allocation> Allocation::createSized2D(const sp<RS>& rs, const sp<const Element>& e,
                                       size_t x, size_t y, uint32_t usage) {
     Type::Builder b(rs, e);
     b.setX(x);
@@ -509,7 +509,7 @@
     return new Surface(bp, true);;
 }
 
-void Allocation::setSurface(RSC::sp<Surface> s) {
+void Allocation::setSurface(const RSC::sp<Surface>& s) {
     if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only set Surface if IO_OUTPUT usage specified.");
         return;
diff --git a/cpp/BaseObj.cpp b/cpp/BaseObj.cpp
index c1a3e55..59eaa9a 100644
--- a/cpp/BaseObj.cpp
+++ b/cpp/BaseObj.cpp
@@ -27,7 +27,7 @@
     return mID;
 }
 
-void * BaseObj::getObjID(sp<const BaseObj> o) {
+void * BaseObj::getObjID(const sp<const BaseObj>& o) {
     return o == nullptr ? nullptr : o->getID();
 }
 
@@ -57,7 +57,7 @@
     mName = name;
 }
 
-bool BaseObj::equals(sp<const BaseObj> obj) {
+bool BaseObj::equals(const sp<const BaseObj>& obj) {
     // Early-out check to see if both BaseObjs are actually the same.
     if (this == obj.get())
         return true;
diff --git a/cpp/Element.cpp b/cpp/Element.cpp
index 9a96ad1..9b4617a 100644
--- a/cpp/Element.cpp
+++ b/cpp/Element.cpp
@@ -72,7 +72,7 @@
 }
 
 
-#define CREATE_USER(N, T) android::RSC::sp<const Element> Element::N(android::RSC::sp<RS> rs) { \
+#define CREATE_USER(N, T) android::RSC::sp<const Element> Element::N(const android::RSC::sp<RS>& rs) { \
     if (rs->mElements.N == nullptr) {                               \
         rs->mElements.N = (createUser(rs, RS_TYPE_##T));            \
     }                                                               \
@@ -100,7 +100,7 @@
 CREATE_USER(MATRIX_3X3, MATRIX_3X3);
 CREATE_USER(MATRIX_2X2, MATRIX_2X2);
 
-#define CREATE_PIXEL(N, T, K) android::RSC::sp<const Element> Element::N(android::RSC::sp<RS> rs) { \
+#define CREATE_PIXEL(N, T, K) android::RSC::sp<const Element> Element::N(const android::RSC::sp<RS> &rs) { \
     if (rs->mElements.N == nullptr) {                                \
         rs->mElements.N = createPixel(rs, RS_TYPE_##T, RS_KIND_##K); \
     }                                                                \
@@ -115,19 +115,19 @@
 CREATE_PIXEL(YUV, UNSIGNED_8, PIXEL_YUV);
 CREATE_PIXEL(RGBA_5551, UNSIGNED_5_5_5_1, PIXEL_RGBA);
 
-#define CREATE_VECTOR(N, T) android::RSC::sp<const Element> Element::N##_2(android::RSC::sp<RS> rs) { \
+#define CREATE_VECTOR(N, T) android::RSC::sp<const Element> Element::N##_2(const android::RSC::sp<RS> &rs) { \
     if (rs->mElements.N##_2 == nullptr) {                                 \
         rs->mElements.N##_2 = createVector(rs, RS_TYPE_##T, 2);           \
     }                                                                     \
     return rs->mElements.N##_2;                                           \
 }                                                                         \
-android::RSC::sp<const Element> Element::N##_3(android::RSC::sp<RS> rs) { \
+android::RSC::sp<const Element> Element::N##_3(const android::RSC::sp<RS> &rs) { \
     if (rs->mElements.N##_3 == nullptr) {                                 \
         rs->mElements.N##_3 = createVector(rs, RS_TYPE_##T, 3);           \
     }                                                                     \
     return rs->mElements.N##_3;                                           \
 } \
-android::RSC::sp<const Element> Element::N##_4(android::RSC::sp<RS> rs) { \
+android::RSC::sp<const Element> Element::N##_4(const android::RSC::sp<RS> &rs) { \
     if (rs->mElements.N##_4 == nullptr) {                                 \
         rs->mElements.N##_4 = createVector(rs, RS_TYPE_##T, 4);           \
     }                                                                     \
@@ -316,12 +316,12 @@
     updateVisibleSubElements();
 }
 
-android::RSC::sp<const Element> Element::createUser(android::RSC::sp<RS> rs, RsDataType dt) {
+android::RSC::sp<const Element> Element::createUser(const android::RSC::sp<RS>& rs, RsDataType dt) {
     void * id = RS::dispatch->ElementCreate(rs->getContext(), dt, RS_KIND_USER, false, 1);
     return new Element(id, rs, dt, RS_KIND_USER, false, 1);
 }
 
-android::RSC::sp<const Element> Element::createVector(android::RSC::sp<RS> rs, RsDataType dt, uint32_t size) {
+android::RSC::sp<const Element> Element::createVector(const android::RSC::sp<RS>& rs, RsDataType dt, uint32_t size) {
     if (size < 2 || size > 4) {
         rs->throwError(RS_ERROR_INVALID_PARAMETER, "Vector size out of range 2-4.");
         return nullptr;
@@ -330,7 +330,7 @@
     return new Element(id, rs, dt, RS_KIND_USER, false, size);
 }
 
-android::RSC::sp<const Element> Element::createPixel(android::RSC::sp<RS> rs, RsDataType dt, RsDataKind dk) {
+android::RSC::sp<const Element> Element::createPixel(const android::RSC::sp<RS>& rs, RsDataType dt, RsDataKind dk) {
     if (!(dk == RS_KIND_PIXEL_L ||
           dk == RS_KIND_PIXEL_A ||
           dk == RS_KIND_PIXEL_LA ||
@@ -388,7 +388,7 @@
     return new Element(id, rs, dt, dk, true, size);
 }
 
-bool Element::isCompatible(android::RSC::sp<const Element>e) const {
+bool Element::isCompatible(const android::RSC::sp<const Element>&e) const {
     // Try strict BaseObj equality to start with.
     if (this == e.get()) {
         return true;
@@ -429,7 +429,7 @@
     free(mArraySizes);
 }
 
-void Element::Builder::add(android::RSC::sp<const Element>e, const char * name, uint32_t arraySize) {
+void Element::Builder::add(const android::RSC::sp<const Element>&e, const char * name, uint32_t arraySize) {
     // Skip padding fields after a vector 3 type.
     if (mSkipPadding) {
         const char *s1 = "#padding_";
diff --git a/cpp/Sampler.cpp b/cpp/Sampler.cpp
index e2e8fac..5aebd86 100644
--- a/cpp/Sampler.cpp
+++ b/cpp/Sampler.cpp
@@ -61,7 +61,7 @@
     return mAniso;
 }
 
-sp<Sampler> Sampler::create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag,
+sp<Sampler> Sampler::create(const sp<RS>& rs, RsSamplerValue min, RsSamplerValue mag,
                             RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy) {
     // We aren't supporting wrapR in C++ API atm, so always pass wrap for that.
     void* id = RS::dispatch->SamplerCreate(rs->getContext(), min, mag, wrapS, wrapT,
@@ -69,7 +69,7 @@
     return new Sampler(rs, id, min, mag, wrapS, wrapT, anisotropy);
 }
 
-#define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(sp<RS> rs) { \
+#define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(const sp<RS> &rs) { \
         if (rs->mSamplers.N == nullptr) {                                \
             rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)); \
         }                                                                \
diff --git a/cpp/Script.cpp b/cpp/Script.cpp
index 52933f2..d0a7d43 100644
--- a/cpp/Script.cpp
+++ b/cpp/Script.cpp
@@ -26,7 +26,7 @@
     tryDispatch(mRS, RS::dispatch->ScriptInvokeV(mRS->getContext(), getID(), slot, v, len));
 }
 
-void Script::forEach(uint32_t slot, sp<const Allocation> ain, sp<const Allocation> aout,
+void Script::forEach(uint32_t slot, const sp<const Allocation>& ain, const sp<const Allocation>& aout,
                        const void *usr, size_t usrLen) const {
     if ((ain == nullptr) && (aout == nullptr)) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "At least one of ain or aout is required to be non-null.");
@@ -40,12 +40,12 @@
 }
 
 
-void Script::bindAllocation(sp<Allocation> va, uint32_t slot) const {
+void Script::bindAllocation(const sp<Allocation>& va, uint32_t slot) const {
     tryDispatch(mRS, RS::dispatch->ScriptBindAllocation(mRS->getContext(), getID(), BaseObj::getObjID(va), slot));
 }
 
 
-void Script::setVar(uint32_t index, sp<const BaseObj> o) const {
+void Script::setVar(uint32_t index, const sp<const BaseObj>& o) const {
     tryDispatch(mRS, RS::dispatch->ScriptSetVarObj(mRS->getContext(), getID(), index, (o == nullptr) ? 0 : o->getID()));
 }
 
@@ -53,6 +53,6 @@
     tryDispatch(mRS, RS::dispatch->ScriptSetVarV(mRS->getContext(), getID(), index, v, len));
 }
 
-void Script::FieldBase::init(sp<RS> rs, uint32_t dimx, uint32_t usages) {
+void Script::FieldBase::init(const sp<RS>& rs, uint32_t dimx, uint32_t usages) {
     mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages);
 }
diff --git a/cpp/ScriptIntrinsicBLAS.cpp b/cpp/ScriptIntrinsicBLAS.cpp
index 63a8f0c..027b8d8 100644
--- a/cpp/ScriptIntrinsicBLAS.cpp
+++ b/cpp/ScriptIntrinsicBLAS.cpp
@@ -27,7 +27,7 @@
 
 }
 
-sp<ScriptIntrinsicBLAS> ScriptIntrinsicBLAS::create(sp<RS> rs) {
+sp<ScriptIntrinsicBLAS> ScriptIntrinsicBLAS::create(const sp<RS>& rs) {
     return new ScriptIntrinsicBLAS(rs, Element::U32(rs));
 }
 
@@ -172,8 +172,8 @@
 /**
  * Level 2 BLAS
  */
-static void validateGEMV(RS* mRS, sp<const Element> e, RsBlasTranspose TransA, sp<Allocation> A,
-                         sp<Allocation> X, int incX, sp<Allocation> Y, int incY) {
+static void validateGEMV(RS* mRS, const sp<const Element>& e, RsBlasTranspose TransA, const sp<Allocation>& A,
+                         const sp<Allocation>& X, int incX, const sp<Allocation>& Y, int incY) {
     int M = A->getType()->getY();
     int N = A->getType()->getX();
     if (!A->getType()->getElement()->isCompatible(e) ||
@@ -202,8 +202,8 @@
     }
 }
 
-void ScriptIntrinsicBLAS::SGEMV(RsBlasTranspose TransA, float alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, float beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::SGEMV(RsBlasTranspose TransA, float alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, float beta, const sp<Allocation>& Y, int incY) {
     validateGEMV(mRS, Element::F32(mRS), TransA, A, X, incX, Y, incY);
     int M = A->getType()->getY();
     int N = A->getType()->getX();
@@ -213,8 +213,8 @@
                                 beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DGEMV(RsBlasTranspose TransA, double alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, double beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::DGEMV(RsBlasTranspose TransA, double alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, double beta, const sp<Allocation>& Y, int incY) {
     validateGEMV(mRS, Element::F64(mRS), TransA, A, X, incX, Y, incY);
     int M = A->getType()->getY();
     int N = A->getType()->getX();
@@ -224,8 +224,8 @@
                                 beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CGEMV(RsBlasTranspose TransA, Float2 alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, Float2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::CGEMV(RsBlasTranspose TransA, Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, Float2 beta, const sp<Allocation>& Y, int incY) {
     validateGEMV(mRS, Element::F32_2(mRS), TransA, A, X, incX, Y, incY);
     int M = A->getType()->getY();
     int N = A->getType()->getX();
@@ -235,8 +235,8 @@
                                  beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZGEMV(RsBlasTranspose TransA, Double2 alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, Double2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::ZGEMV(RsBlasTranspose TransA, Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, Double2 beta, const sp<Allocation>& Y, int incY) {
     validateGEMV(mRS, Element::F64_2(mRS), TransA, A, X, incX, Y, incY);
     int M = A->getType()->getY();
     int N = A->getType()->getX();
@@ -246,8 +246,8 @@
                            beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SGBMV(RsBlasTranspose TransA, int KL, int KU, float alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, float beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::SGBMV(RsBlasTranspose TransA, int KL, int KU, float alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, float beta, const sp<Allocation>& Y, int incY) {
     // GBMV has the same validation requirements as GEMV + KL and KU >= 0
     validateGEMV(mRS, Element::F32(mRS), TransA, A, X, incX, Y, incY);
     if (KL < 0 || KU < 0) {
@@ -262,8 +262,8 @@
                                 beta, Y->getID(), incX, incY, KL, KU);
 }
 
-void ScriptIntrinsicBLAS::DGBMV(RsBlasTranspose TransA, int KL, int KU, double alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, double beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::DGBMV(RsBlasTranspose TransA, int KL, int KU, double alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, double beta, const sp<Allocation>& Y, int incY) {
     // GBMV has the same validation requirements as GEMV + KL and KU >= 0
     validateGEMV(mRS, Element::F64(mRS), TransA, A, X, incX, Y, incY);
     if (KL < 0 || KU < 0) {
@@ -278,8 +278,8 @@
                                 beta, Y->getID(), incX, incY, KL, KU);
 }
 
-void ScriptIntrinsicBLAS::CGBMV(RsBlasTranspose TransA, int KL, int KU, Float2 alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, Float2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::CGBMV(RsBlasTranspose TransA, int KL, int KU, Float2 alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, Float2 beta, const sp<Allocation>& Y, int incY) {
     // GBMV has the same validation requirements as GEMV + KL and KU >= 0
     validateGEMV(mRS, Element::F32_2(mRS), TransA, A, X, incX, Y, incY);
     if (KL < 0 || KU < 0) {
@@ -294,8 +294,8 @@
                                  beta.x, beta.y, Y->getID(), incX, incY, KL, KU);
 }
 
-void ScriptIntrinsicBLAS::ZGBMV(RsBlasTranspose TransA, int KL, int KU, Double2 alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, Double2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::ZGBMV(RsBlasTranspose TransA, int KL, int KU, Double2 alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, Double2 beta, const sp<Allocation>& Y, int incY) {
     // GBMV has the same validation requirements as GEMV + KL and KU >= 0
     validateGEMV(mRS, Element::F64_2(mRS), TransA, A, X, incX, Y, incY);
     if (KL < 0 || KU < 0) {
@@ -310,8 +310,8 @@
                            beta.x, beta.y, Y->getID(), incX, incY, KL, KU);
 }
 
-static void validateTRMV(RS* mRS, sp<const Element> e, RsBlasUplo Uplo, RsBlasTranspose TransA,
-                         RsBlasDiag Diag, sp<Allocation> A, sp<Allocation> X, int incX) {
+static void validateTRMV(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo, RsBlasTranspose TransA,
+                         RsBlasDiag Diag, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     int N = A->getType()->getY();
     if ((int)A->getType()->getX() != N) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "A must be a square matrix for TRMV");
@@ -333,8 +333,8 @@
     }
 }
 
-static int validateTPMV(RS* mRS, sp<const Element> e,  RsBlasUplo Uplo, RsBlasTranspose TransA,
-                        RsBlasDiag Diag, sp<Allocation> Ap, sp<Allocation> X, int incX) {
+static int validateTPMV(RS* mRS, const sp<const Element>& e,  RsBlasUplo Uplo, RsBlasTranspose TransA,
+                        RsBlasDiag Diag, const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     if (!Ap->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e)) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Called BLAS with wrong Element type");
@@ -364,7 +364,7 @@
 
 
 void ScriptIntrinsicBLAS::STRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     validateTRMV(mRS, Element::F32(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_strmv,
@@ -373,7 +373,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     validateTRMV(mRS, Element::F64(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dtrmv,
@@ -382,7 +382,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     validateTRMV(mRS, Element::F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_ctrmv,
@@ -391,7 +391,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     validateTRMV(mRS, Element::F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_ztrmv,
@@ -400,7 +400,7 @@
 }
 
 void ScriptIntrinsicBLAS::STBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBMV has the same requirements as TRMV + K >= 0
     if (K < 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "K must be greater than or equal to 0");
@@ -413,7 +413,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBMV has the same requirements as TRMV + K >= 0
     if (K < 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "K must be greater than or equal to 0");
@@ -426,7 +426,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBMV has the same requirements as TRMV + K >= 0
     if (K < 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "K must be greater than or equal to 0");
@@ -439,7 +439,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBMV has the same requirements as TRMV + K >= 0
     if (K < 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "K must be greater than or equal to 0");
@@ -452,7 +452,7 @@
 }
 
 void ScriptIntrinsicBLAS::STPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     int N = validateTPMV(mRS, Element::F32(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_stpmv,
                                 TransA, 0, 0, Uplo, Diag, 0, N, 0, 0,
@@ -460,7 +460,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     int N = validateTPMV(mRS, Element::F64(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dtpmv,
                                 TransA, 0, 0, Uplo, Diag, 0, N, 0, 0,
@@ -468,7 +468,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap,  sp<Allocation> X,  int incX) {
+                                const sp<Allocation>& Ap,  const sp<Allocation>& X,  int incX) {
     int N = validateTPMV(mRS, Element::F32_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_ctpmv,
                                  TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0,
@@ -476,7 +476,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     int N = validateTPMV(mRS, Element::F64_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_ztpmv,
                            TransA, 0, 0, Uplo, Diag, 0, N, 0, 0, 0,
@@ -484,7 +484,7 @@
 }
 
 void ScriptIntrinsicBLAS::STRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TRSV is the same as TRMV
     validateTRMV(mRS, Element::F32(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -494,7 +494,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A,  sp<Allocation> X,  int incX) {
+                                const sp<Allocation>& A,  const sp<Allocation>& X,  int incX) {
     // TRSV is the same as TRMV
     validateTRMV(mRS, Element::F64(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -505,7 +505,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TRSV is the same as TRMV
     validateTRMV(mRS, Element::F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -516,7 +516,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> A, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TRSV is the same as TRMV
     validateTRMV(mRS, Element::F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -527,7 +527,7 @@
 }
 
 void ScriptIntrinsicBLAS::STBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBSV is the same as TRMV + K >= 0
     validateTRMV(mRS, Element::F32(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -540,7 +540,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBSV is the same as TRMV + K >= 0
     validateTRMV(mRS, Element::F64(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -553,7 +553,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBSV is the same as TRMV + K >= 0
     validateTRMV(mRS, Element::F32_2(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -566,7 +566,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                int K, sp<Allocation> A, sp<Allocation> X, int incX) {
+                                int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX) {
     // TBSV is the same as TRMV + K >= 0
     validateTRMV(mRS, Element::F64_2(mRS), Uplo, TransA, Diag, A, X, incX);
     int N = A->getType()->getY();
@@ -579,7 +579,7 @@
 }
 
 void ScriptIntrinsicBLAS::STPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     // TPSV is same as TPMV
     int N = validateTPMV(mRS, Element::F32(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_stpsv,
@@ -588,7 +588,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     // TPSV is same as TPMV
     int N = validateTPMV(mRS, Element::F64(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dtpsv,
@@ -597,7 +597,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     // TPSV is same as TPMV
     int N = validateTPMV(mRS, Element::F32_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_ctpsv,
@@ -606,7 +606,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                sp<Allocation> Ap, sp<Allocation> X, int incX) {
+                                const sp<Allocation>& Ap, const sp<Allocation>& X, int incX) {
     // TPSV is same as TPMV
     int N = validateTPMV(mRS, Element::F64_2(mRS), Uplo, TransA, Diag, Ap, X, incX);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_ztpsv,
@@ -617,8 +617,8 @@
 /**
  * Level 2, S and D only
  */
-static int validateSYMV(RS* mRS, sp<const Element> e, RsBlasUplo Uplo, sp<Allocation> A,
-                        sp<Allocation> X, sp<Allocation> Y, int incX, int incY) {
+static int validateSYMV(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo, const sp<Allocation>& A,
+                        const sp<Allocation>& X, const sp<Allocation>& Y, int incX, int incY) {
     int N = A->getType()->getY();
     if ((int)A->getType()->getX() != N) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "A must be a square matrix for SYMV");
@@ -645,8 +645,8 @@
     }
     return N;
 }
-static int validateSPMV(RS* mRS, sp<const Element> e, RsBlasUplo Uplo, sp<Allocation> Ap,
-                        sp<Allocation> X, int incX, sp<Allocation> Y, int incY) {
+static int validateSPMV(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo, const sp<Allocation>& Ap,
+                        const sp<Allocation>& X, int incX, const sp<Allocation>& Y, int incY) {
     if (!Ap->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e) ||
         !Y->getType()->getElement()->isCompatible(e)) {
@@ -678,8 +678,8 @@
 
     return N;
 }
-static void validateGER(RS* mRS, sp<const Element> e, sp<Allocation> X, int incX,
-                        sp<Allocation> Y, int incY, sp<Allocation> A) {
+static void validateGER(RS* mRS, const sp<const Element>& e, const sp<Allocation>& X, int incX,
+                        const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e) ||
         !Y->getType()->getElement()->isCompatible(e) ) {
@@ -710,8 +710,8 @@
 
 
 }
-static int validateSYR(RS* mRS, sp<const Element> e, RsBlasUplo Uplo,
-                       sp<Allocation> X, int incX, sp<Allocation> A) {
+static int validateSYR(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo,
+                       const sp<Allocation>& X, int incX, const sp<Allocation>& A) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e)) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Called BLAS with wrong Element type");
@@ -734,8 +734,8 @@
     }
     return N;
 }
-static int validateSPR(RS* mRS, sp<const Element> e, RsBlasUplo Uplo,
-                       sp<Allocation> X, int incX, sp<Allocation> Ap) {
+static int validateSPR(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo,
+                       const sp<Allocation>& X, int incX, const sp<Allocation>& Ap) {
     if (!Ap->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e)) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Called BLAS with wrong Element type");
@@ -763,8 +763,8 @@
     return N;
 }
 
-static int validateSYR2(RS* mRS, sp<const Element> e, RsBlasUplo Uplo, sp<Allocation> X,
-                        int incX, sp<Allocation> Y, int incY, sp<Allocation> A) {
+static int validateSYR2(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo, const sp<Allocation>& X,
+                        int incX, const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e) ||
         !Y->getType()->getElement()->isCompatible(e)) {
@@ -791,8 +791,8 @@
     return N;
 
 }
-static int validateSPR2(RS* mRS, sp<const Element> e, RsBlasUplo Uplo, sp<Allocation> X,
-                        int incX, sp<Allocation> Y, int incY, sp<Allocation> Ap) {
+static int validateSPR2(RS* mRS, const sp<const Element>& e, RsBlasUplo Uplo, const sp<Allocation>& X,
+                        int incX, const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap) {
     if (!Ap->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e) ||
         !Y->getType()->getElement()->isCompatible(e)) {
@@ -822,16 +822,16 @@
     return N;
 }
 
-void ScriptIntrinsicBLAS::SSYMV(RsBlasUplo Uplo, float alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, float beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::SSYMV(RsBlasUplo Uplo, float alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, float beta, const sp<Allocation>& Y, int incY) {
     int N = validateSYMV(mRS, Element::F32(mRS), Uplo, A, X, Y, incX, incY);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_ssymv,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 A->getID(), X->getID(), beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SSBMV(RsBlasUplo Uplo, int K, float alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, float beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::SSBMV(RsBlasUplo Uplo, int K, float alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, float beta, const sp<Allocation>& Y, int incY) {
     // SBMV is the same as SYMV + K >= 0
     if (K < 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "K must be greater than or equal to 0");
@@ -842,16 +842,16 @@
                                 A->getID(), X->getID(), beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SSPMV(RsBlasUplo Uplo, float alpha, sp<Allocation> Ap, sp<Allocation> X,
-                                int incX, float beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::SSPMV(RsBlasUplo Uplo, float alpha, const sp<Allocation>& Ap, const sp<Allocation>& X,
+                                int incX, float beta, const sp<Allocation>& Y, int incY) {
     int N = validateSPMV(mRS, Element::F32(mRS), Uplo, Ap, X, incX, Y, incY);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_sspmv,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 Ap->getID(), X->getID(), beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SGER(float alpha, sp<Allocation> X, int incX,
-                               sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::SGER(float alpha, const sp<Allocation>& X, int incX,
+                               const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     int M = A->getType()->getY();
     int N = A->getType()->getX();
     validateGER(mRS, Element::F32(mRS), X, incX, Y, incY, A);
@@ -860,48 +860,48 @@
                                 X->getID(), Y->getID(), 0.f, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SSYR(RsBlasUplo Uplo, float alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::SSYR(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& A) {
     int N = validateSYR(mRS, Element::F32(mRS), Uplo, X, incX, A);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_ssyr,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 X->getID(), A->getID(), 0.f, 0, incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SSPR(RsBlasUplo Uplo, float alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::SSPR(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& Ap) {
     int N = validateSPR(mRS, Element::F32(mRS), Uplo, X, incX, Ap);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_sspr,
                                 0, 0, 0, Uplo, 0, 0, N, 0,
                                 alpha, X->getID(), Ap->getID(), 0.f, 0, incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SSYR2(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::SSYR2(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     int N = validateSYR2(mRS, Element::F32(mRS), Uplo, X, incX, Y, incY, A);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_ssyr2,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 X->getID(), Y->getID(), 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::SSPR2(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::SSPR2(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap) {
     int N = validateSPR2(mRS, Element::F32(mRS), Uplo, X, incX, Y, incY, Ap);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_sspr2,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 X->getID(), Y->getID(), 0, Ap->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSYMV(RsBlasUplo Uplo, double alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, double beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::DSYMV(RsBlasUplo Uplo, double alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, double beta, const sp<Allocation>& Y, int incY) {
     int N = validateSYMV(mRS, Element::F64(mRS), Uplo, A, X, Y, incX, incY);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dsymv,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 A->getID(), X->getID(), beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSBMV(RsBlasUplo Uplo, int K, double alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, double beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::DSBMV(RsBlasUplo Uplo, int K, double alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, double beta, const sp<Allocation>& Y, int incY) {
     // SBMV is the same as SYMV + K >= 0
     if (K < 0) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "K must be greater than or equal to 0");
@@ -912,16 +912,16 @@
                                 A->getID(), X->getID(), beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSPMV(RsBlasUplo Uplo, double alpha, sp<Allocation> Ap, sp<Allocation> X,
-                                int incX, double beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::DSPMV(RsBlasUplo Uplo, double alpha, const sp<Allocation>& Ap, const sp<Allocation>& X,
+                                int incX, double beta, const sp<Allocation>& Y, int incY) {
     int N = validateSPMV(mRS, Element::F64(mRS), Uplo, Ap, X, incX, Y, incY);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dspmv,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 Ap->getID(), X->getID(), beta, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DGER(double alpha, sp<Allocation> X, int incX, sp<Allocation> Y,
-                               int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::DGER(double alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Y,
+                               int incY, const sp<Allocation>& A) {
     int M = A->getType()->getY();
     int N = A->getType()->getX();
     validateGER(mRS, Element::F64(mRS), X, incX, Y, incY, A);
@@ -930,32 +930,32 @@
                                 X->getID(), Y->getID(), 0.f, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSYR(RsBlasUplo Uplo, double alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::DSYR(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& A) {
     int N = validateSYR(mRS, Element::F64(mRS), Uplo, X, incX, A);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dsyr,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 X->getID(), A->getID(), 0.f, 0, incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSPR(RsBlasUplo Uplo, double alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::DSPR(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& Ap) {
     int N = validateSPR(mRS, Element::F64(mRS), Uplo, X, incX, Ap);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dspr,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 X->getID(), Ap->getID(), 0.f, 0, incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSYR2(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::DSYR2(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     int N = validateSYR2(mRS, Element::F64(mRS), Uplo, X, incX, Y, incY, A);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dsyr2,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
                                 X->getID(), Y->getID(), 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::DSPR2(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::DSPR2(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap) {
     int N = validateSPR2(mRS, Element::F64(mRS), Uplo, X, incX, Y, incY, Ap);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dspr2,
                                 0, 0, 0, Uplo, 0, 0, N, 0, alpha,
@@ -967,8 +967,8 @@
  * Level 2, C and Z only
  */
 
-static void validateGERU(RS* mRS, sp<const Element> e, sp<Allocation> X, int incX,
-                         sp<Allocation> Y, int incY, sp<Allocation> A) {
+static void validateGERU(RS* mRS, const sp<const Element>& e, const sp<Allocation>& X, int incX,
+                         const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !X->getType()->getElement()->isCompatible(e) ||
         !Y->getType()->getElement()->isCompatible(e)) {
@@ -994,8 +994,8 @@
 
 }
 
-void ScriptIntrinsicBLAS::CHEMV(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, Float2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::CHEMV(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, Float2 beta, const sp<Allocation>& Y, int incY) {
     // HEMV is the same as SYR2 validation-wise
     int N = validateSYR2(mRS, Element::F32_2(mRS), Uplo, X, incX, Y, incY, A);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_chemv,
@@ -1004,8 +1004,8 @@
                                  beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CHBMV(RsBlasUplo Uplo, int K, Float2 alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, Float2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::CHBMV(RsBlasUplo Uplo, int K, Float2 alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, Float2 beta, const sp<Allocation>& Y, int incY) {
     // HBMV is the same as SYR2 validation-wise
     int N = validateSYR2(mRS, Element::F32_2(mRS), Uplo, X, incX, Y, incY, A);
     if (K < 0) {
@@ -1017,8 +1017,8 @@
                                  beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CHPMV(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> Ap,
-                                sp<Allocation> X, int incX, Float2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::CHPMV(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& Ap,
+                                const sp<Allocation>& X, int incX, Float2 beta, const sp<Allocation>& Y, int incY) {
     // HPMV is the same as SPR2
     int N = validateSPR2(mRS, Element::F32_2(mRS), Uplo, X, incX, Y, incY, Ap);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_chpmv,
@@ -1027,8 +1027,8 @@
                                  beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CGERU(Float2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::CGERU(Float2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     validateGERU(mRS, Element::F32_2(mRS), X, incX, Y, incY, A);
     int M = A->getType()->getY();
     int N = A->getType()->getX();
@@ -1038,8 +1038,8 @@
                                  0, 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CGERC(Float2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::CGERC(Float2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     // Same as GERU
     validateGERU(mRS, Element::F32_2(mRS), X, incX, Y, incY, A);
     int M = A->getType()->getY();
@@ -1050,8 +1050,8 @@
                                  0, 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CHER(RsBlasUplo Uplo, float alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::CHER(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& A) {
     // Same as SYR
     int N = validateSYR(mRS, Element::F32_2(mRS), Uplo, X, incX, A);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_cher,
@@ -1060,8 +1060,8 @@
                                  0, 0, A->getID(), incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CHPR(RsBlasUplo Uplo, float alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::CHPR(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& Ap) {
     // Equivalent to SPR for validation
     int N = validateSPR(mRS, Element::F32_2(mRS), Uplo, X, incX, Ap);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_chpr,
@@ -1070,8 +1070,8 @@
                                  0, 0, Ap->getID(), incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CHER2(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::CHER2(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     // Same as SYR2
     int N = validateSYR2(mRS, Element::F32_2(mRS), Uplo, X, incX, Y, incY, A);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_cher2,
@@ -1080,8 +1080,8 @@
                                  0, 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::CHPR2(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::CHPR2(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap) {
     // Same as SPR2
     int N = validateSPR2(mRS, Element::F32_2(mRS), Uplo, X, incX, Y, incY, Ap);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_chpr2,
@@ -1090,8 +1090,8 @@
                                  0, 0, Ap->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHEMV(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> A,
-                                sp<Allocation> X, int incX, Double2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::ZHEMV(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& A,
+                                const sp<Allocation>& X, int incX, Double2 beta, const sp<Allocation>& Y, int incY) {
     // HEMV is the same as SYR2 validation-wise
     int N = validateSYR2(mRS, Element::F64_2(mRS), Uplo, X, incX, Y, incY, A);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zhemv,
@@ -1100,8 +1100,8 @@
                            beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHBMV(RsBlasUplo Uplo, int K, Double2 alpha, sp<Allocation> A, sp<Allocation> X,
-                                int incX, Double2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::ZHBMV(RsBlasUplo Uplo, int K, Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+                                int incX, Double2 beta, const sp<Allocation>& Y, int incY) {
     // HBMV is the same as SYR2 validation-wise
     int N = validateSYR2(mRS, Element::F64_2(mRS), Uplo, X, incX, Y, incY, A);
     if (K < 0) {
@@ -1113,8 +1113,8 @@
                            beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHPMV(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> Ap, sp<Allocation> X,
-                                int incX, Double2 beta, sp<Allocation> Y, int incY) {
+void ScriptIntrinsicBLAS::ZHPMV(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& Ap, const sp<Allocation>& X,
+                                int incX, Double2 beta, const sp<Allocation>& Y, int incY) {
     // HPMV is the same as SPR2
     int N = validateSPR2(mRS, Element::F64_2(mRS), Uplo, X, incX, Y, incY, Ap);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zhpmv,
@@ -1123,8 +1123,8 @@
                            beta.x, beta.y, Y->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZGERU(Double2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::ZGERU(Double2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     validateGERU(mRS, Element::F64_2(mRS), X, incX, Y, incY, A);
     int M = A->getType()->getY();
     int N = A->getType()->getX();
@@ -1134,8 +1134,8 @@
                            0, 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZGERC(Double2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::ZGERC(Double2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     // Same as GERU
     validateGERU(mRS, Element::F64_2(mRS), X, incX, Y, incY, A);
     int M = A->getType()->getY();
@@ -1146,8 +1146,8 @@
                            0, 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHER(RsBlasUplo Uplo, double alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::ZHER(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& A) {
     // Same as SYR
     int N = validateSYR(mRS, Element::F64_2(mRS), Uplo, X, incX, A);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zher,
@@ -1156,8 +1156,8 @@
                            0, 0, A->getID(), incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHPR(RsBlasUplo Uplo, double alpha, sp<Allocation> X,
-                               int incX, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::ZHPR(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X,
+                               int incX, const sp<Allocation>& Ap) {
     // Equivalent to SPR for validation
     int N = validateSPR(mRS, Element::F64_2(mRS), Uplo, X, incX, Ap);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zhpr,
@@ -1166,8 +1166,8 @@
                            0, 0, Ap->getID(), incX, 0, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHER2(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> A) {
+void ScriptIntrinsicBLAS::ZHER2(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& A) {
     // Same as SYR2
     int N = validateSYR2(mRS, Element::F64_2(mRS), Uplo, X, incX, Y, incY, A);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zher2,
@@ -1176,8 +1176,8 @@
                            0, 0, A->getID(), incX, incY, 0, 0);
 }
 
-void ScriptIntrinsicBLAS::ZHPR2(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> X, int incX,
-                                sp<Allocation> Y, int incY, sp<Allocation> Ap) {
+void ScriptIntrinsicBLAS::ZHPR2(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& X, int incX,
+                                const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap) {
     // Same as SPR2
     int N = validateSPR2(mRS, Element::F64_2(mRS), Uplo, X, incX, Y, incY, Ap);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zhpr2,
@@ -1191,8 +1191,8 @@
  * Level 3 BLAS
  */
 
-static void validateL3(RS* mRS, sp<const Element> e, int TransA, int TransB, int Side,
-                       sp<Allocation> A, sp<Allocation> B, sp<Allocation> C) {
+static void validateL3(RS* mRS, const sp<const Element>& e, int TransA, int TransB, int Side,
+                       const sp<Allocation>& A, const sp<Allocation>& B, const sp<Allocation>& C) {
     int aM = -1, aN = -1, bM = -1, bN = -1, cM = -1, cN = -1;
     if ((A != nullptr && !A->getType()->getElement()->isCompatible(e)) ||
         (B != nullptr && !B->getType()->getElement()->isCompatible(e)) ||
@@ -1260,7 +1260,7 @@
 }
 
 void ScriptIntrinsicBLAS::SGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, float alpha,
-                                sp<Allocation> A, sp<Allocation> B, float beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, float beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F32(mRS), TransA, TransB, 0, A, B, C);
 
     int M = -1, N = -1, K = -1;
@@ -1283,7 +1283,7 @@
 }
 
 void ScriptIntrinsicBLAS::DGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, double alpha,
-                                sp<Allocation> A, sp<Allocation> B, double beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, double beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F64(mRS), TransA, TransB, 0, A, B, C);
     int M = -1, N = -1, K = -1;
     if (TransA != RsBlasNoTrans) {
@@ -1305,7 +1305,7 @@
 }
 
 void ScriptIntrinsicBLAS::CGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, Float2 alpha,
-                                sp<Allocation> A, sp<Allocation> B, Float2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F32_2(mRS), TransA, TransB, 0, A, B, C);
     int M = -1, N = -1, K = -1;
     if (TransA != RsBlasNoTrans) {
@@ -1327,7 +1327,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, Double2 alpha,
-                                sp<Allocation> A, sp<Allocation> B, Double2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F64_2(mRS), TransA, TransB, 0, A, B, C);
     int M = -1, N = -1, K = -1;
     if (TransA != RsBlasNoTrans) {
@@ -1349,7 +1349,7 @@
 }
 
 void ScriptIntrinsicBLAS::SSYMM(RsBlasSide Side, RsBlasUplo Uplo, float alpha,
-                                sp<Allocation> A, sp<Allocation> B, float beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, float beta, const sp<Allocation>& C) {
     //For SYMM, Matrix A should be symmetric
     if (A->getType()->getX() != A->getType()->getY()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Matrix A is not symmetric");
@@ -1362,7 +1362,7 @@
 }
 
 void ScriptIntrinsicBLAS::DSYMM(RsBlasSide Side, RsBlasUplo Uplo, double alpha,
-                                sp<Allocation> A, sp<Allocation> B, double beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, double beta, const sp<Allocation>& C) {
     if (A->getType()->getX() != A->getType()->getY()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Matrix A is not symmetric");
     }
@@ -1374,7 +1374,7 @@
 }
 
 void ScriptIntrinsicBLAS::CSYMM(RsBlasSide Side, RsBlasUplo Uplo, Float2 alpha,
-                                sp<Allocation> A, sp<Allocation> B, Float2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C) {
     if (A->getType()->getX() != A->getType()->getY()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Matrix A is not symmetric");
     }
@@ -1386,7 +1386,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZSYMM(RsBlasSide Side, RsBlasUplo Uplo, Double2 alpha,
-                                sp<Allocation> A, sp<Allocation> B, Double2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C) {
     if (A->getType()->getX() != A->getType()->getY()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Matrix A is not symmetric");
     }
@@ -1398,7 +1398,7 @@
 }
 
 void ScriptIntrinsicBLAS::SSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha,
-                                sp<Allocation> A, float beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, float beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F32(mRS), Trans, 0, 0, A, nullptr, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1413,7 +1413,7 @@
 }
 
 void ScriptIntrinsicBLAS::DSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha,
-                                sp<Allocation> A, double beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, double beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F64(mRS), Trans, 0, 0, A, nullptr, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1428,7 +1428,7 @@
 }
 
 void ScriptIntrinsicBLAS::CSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha,
-                                sp<Allocation> A, Float2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, Float2 beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F32_2(mRS), Trans, 0, 0, A, nullptr, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1443,7 +1443,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha,
-                                sp<Allocation> A, Double2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, Double2 beta, const sp<Allocation>& C) {
     validateL3(mRS, Element::F64_2(mRS), Trans, 0, 0, A, nullptr, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1457,8 +1457,8 @@
                            beta.x, beta.y, C->getID(), 0, 0, 0, 0);
 }
 
-static void validateSYR2K(RS* mRS, sp<const Element> e, RsBlasTranspose Trans,
-                          sp<Allocation> A, sp<Allocation> B, sp<Allocation> C) {
+static void validateSYR2K(RS* mRS, const sp<const Element>& e, RsBlasTranspose Trans,
+                          const sp<Allocation>& A, const sp<Allocation>& B, const sp<Allocation>& C) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !B->getType()->getElement()->isCompatible(e) ||
         !C->getType()->getElement()->isCompatible(e)) {
@@ -1484,7 +1484,7 @@
 }
 
 void ScriptIntrinsicBLAS::SSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha,
-                                 sp<Allocation> A, sp<Allocation> B, float beta, sp<Allocation> C) {
+                                 const sp<Allocation>& A, const sp<Allocation>& B, float beta, const sp<Allocation>& C) {
     validateSYR2K(mRS, Element::F32(mRS), Trans, A, B, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1499,7 +1499,7 @@
 }
 
 void ScriptIntrinsicBLAS::DSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha,
-                                 sp<Allocation> A, sp<Allocation> B, double beta, sp<Allocation> C) {
+                                 const sp<Allocation>& A, const sp<Allocation>& B, double beta, const sp<Allocation>& C) {
     validateSYR2K(mRS, Element::F64(mRS), Trans, A, B, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1514,7 +1514,7 @@
 }
 
 void ScriptIntrinsicBLAS::CSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha,
-                                 sp<Allocation> A, sp<Allocation> B, Float2 beta, sp<Allocation> C) {
+                                 const sp<Allocation>& A, const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C) {
     validateSYR2K(mRS, Element::F32_2(mRS), Trans, A, B, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1529,7 +1529,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha,
-                                 sp<Allocation> A, sp<Allocation> B, Double2 beta, sp<Allocation> C) {
+                                 const sp<Allocation>& A, const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C) {
     validateSYR2K(mRS, Element::F64_2(mRS), Trans, A, B, C);
     int K = -1;
     if (Trans != RsBlasNoTrans) {
@@ -1543,8 +1543,8 @@
                            beta.x, beta.y, C->getID(), 0, 0, 0, 0);
 }
 
-static void validateTRMM(RS* mRS, sp<const Element> e, RsBlasSide Side, RsBlasTranspose TransA,
-                         sp<Allocation> A, sp<Allocation> B) {
+static void validateTRMM(RS* mRS, const sp<const Element>& e, RsBlasSide Side, RsBlasTranspose TransA,
+                         const sp<Allocation>& A, const sp<Allocation>& B) {
     int aM = -1, aN = -1, bM = -1, bN = -1;
     if (!A->getType()->getElement()->isCompatible(e) ||
         !B->getType()->getElement()->isCompatible(e)) {
@@ -1571,7 +1571,7 @@
 }
 
 void ScriptIntrinsicBLAS::STRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                float alpha, sp<Allocation> A, sp<Allocation> B) {
+                                float alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRMM(mRS, Element::F32(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_strmm,
                                 TransA, 0, Side, Uplo, Diag,\
@@ -1580,7 +1580,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                double alpha, sp<Allocation> A, sp<Allocation> B) {
+                                double alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRMM(mRS, Element::F64(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dtrmm,
                                 TransA, 0, Side, Uplo, Diag,
@@ -1589,7 +1589,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                Float2 alpha, sp<Allocation> A, sp<Allocation> B) {
+                                Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRMM(mRS, Element::F32_2(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_ctrmm,
                                  TransA, 0, Side, Uplo, Diag,
@@ -1598,7 +1598,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                Double2 alpha, sp<Allocation> A, sp<Allocation> B) {
+                                Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRMM(mRS, Element::F64_2(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_ztrmm,
                            TransA, 0, Side, Uplo, Diag,
@@ -1606,8 +1606,8 @@
                            alpha.x, alpha.y, A->getID(), B->getID(), 0, 0, 0, 0, 0, 0, 0);
 }
 
-static void validateTRSM(RS* mRS, sp<const Element> e, RsBlasSide Side, RsBlasTranspose TransA,
-                         sp<Allocation> A, sp<Allocation> B) {
+static void validateTRSM(RS* mRS, const sp<const Element>& e, RsBlasSide Side, RsBlasTranspose TransA,
+                         const sp<Allocation>& A, const sp<Allocation>& B) {
     int adim = -1, bM = -1, bN = -1;
     if (!A->getType()->getElement()->isCompatible(e) ||
         !B->getType()->getElement()->isCompatible(e)) {
@@ -1636,7 +1636,7 @@
 }
 
 void ScriptIntrinsicBLAS::STRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                float alpha, sp<Allocation> A, sp<Allocation> B) {
+                                float alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRSM(mRS, Element::F32(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Single(mRS, mRS->getContext(), getID(), RsBlas_strsm,
                                 TransA, 0, Side, Uplo, Diag,
@@ -1645,7 +1645,7 @@
 }
 
 void ScriptIntrinsicBLAS::DTRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                double alpha, sp<Allocation> A, sp<Allocation> B) {
+                                double alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRSM(mRS, Element::F64(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Double(mRS, mRS->getContext(), getID(), RsBlas_dtrsm,
                                 TransA, 0, Side, Uplo, Diag,
@@ -1654,7 +1654,7 @@
 }
 
 void ScriptIntrinsicBLAS::CTRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                Float2 alpha, sp<Allocation> A, sp<Allocation> B) {
+                                Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRSM(mRS, Element::F32_2(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_ctrsm,
                                  TransA, 0, Side, Uplo, Diag,
@@ -1663,7 +1663,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZTRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-                                Double2 alpha, sp<Allocation> A, sp<Allocation> B) {
+                                Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& B) {
     validateTRSM(mRS, Element::F64_2(mRS), Side, TransA, A, B);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_ztrsm,
                            TransA, 0, Side, Uplo, Diag,
@@ -1671,8 +1671,8 @@
                            alpha.x, alpha.y, A->getID(), B->getID(), 0, 0, 0, 0, 0, 0, 0);
 }
 
-static void validateHEMM(RS* mRS, sp<const Element> e, RsBlasSide Side,
-                         sp<Allocation> A, sp<Allocation> B, sp<Allocation> C) {
+static void validateHEMM(RS* mRS, const sp<const Element>& e, RsBlasSide Side,
+                         const sp<Allocation>& A, const sp<Allocation>& B, const sp<Allocation>& C) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !B->getType()->getElement()->isCompatible(e) ||
         !C->getType()->getElement()->isCompatible(e)) {
@@ -1695,7 +1695,7 @@
 }
 
 void ScriptIntrinsicBLAS::CHEMM(RsBlasSide Side, RsBlasUplo Uplo, Float2 alpha,
-                                sp<Allocation> A, sp<Allocation> B, Float2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C) {
     validateHEMM(mRS, Element::F32_2(mRS), Side, A, B, C);
     nScriptIntrinsicBLAS_Complex(mRS, mRS->getContext(), getID(), RsBlas_chemm,
                                  0, 0, Side, Uplo, 0,
@@ -1705,7 +1705,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZHEMM(RsBlasSide Side, RsBlasUplo Uplo, Double2 alpha,
-                                sp<Allocation> A, sp<Allocation> B, Double2 beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C) {
     validateHEMM(mRS, Element::F64_2(mRS), Side, A, B, C);
     nScriptIntrinsicBLAS_Z(mRS, mRS->getContext(), getID(), RsBlas_zhemm,
                            0, 0, Side, Uplo, 0,
@@ -1714,8 +1714,8 @@
                            beta.x, beta.y, C->getID(), 0, 0, 0, 0);
 }
 
-static void validateHERK(RS* mRS, sp<const Element> e, RsBlasTranspose Trans,
-                         sp<Allocation> A, sp<Allocation> C) {
+static void validateHERK(RS* mRS, const sp<const Element>& e, RsBlasTranspose Trans,
+                         const sp<Allocation>& A, const sp<Allocation>& C) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !C->getType()->getElement()->isCompatible(e)) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Called BLAS with wrong Element type");
@@ -1739,7 +1739,7 @@
 }
 
 void ScriptIntrinsicBLAS::CHERK(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha,
-                                sp<Allocation> A, float beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, float beta, const sp<Allocation>& C) {
     validateHERK(mRS, Element::F32_2(mRS), Trans, A, C);
     int k = 0;
     if (Trans == RsBlasConjTrans) {
@@ -1754,7 +1754,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZHERK(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha,
-                                sp<Allocation> A, double beta, sp<Allocation> C) {
+                                const sp<Allocation>& A, double beta, const sp<Allocation>& C) {
     validateHERK(mRS, Element::F64_2(mRS), Trans, A, C);
     int k = 0;
     if (Trans == RsBlasConjTrans) {
@@ -1768,8 +1768,8 @@
                            beta, 0, C->getID(), 0, 0, 0, 0);
 }
 
-static void validateHER2K(RS* mRS, sp<const Element> e, RsBlasTranspose Trans,
-                          sp<Allocation> A, sp<Allocation> B, sp<Allocation> C) {
+static void validateHER2K(RS* mRS, const sp<const Element>& e, RsBlasTranspose Trans,
+                          const sp<Allocation>& A, const sp<Allocation>& B, const sp<Allocation>& C) {
     if (!A->getType()->getElement()->isCompatible(e) ||
         !B->getType()->getElement()->isCompatible(e) ||
         !C->getType()->getElement()->isCompatible(e)) {
@@ -1797,7 +1797,7 @@
 }
 
 void ScriptIntrinsicBLAS::CHER2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha,
-                                 sp<Allocation> A, sp<Allocation> B, float beta, sp<Allocation> C) {
+                                 const sp<Allocation>& A, const sp<Allocation>& B, float beta, const sp<Allocation>& C) {
     validateHER2K(mRS, Element::F32_2(mRS), Trans, A, B, C);
     int k = 0;
     if (Trans == RsBlasNoTrans) {
@@ -1812,7 +1812,7 @@
 }
 
 void ScriptIntrinsicBLAS::ZHER2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha,
-                                 sp<Allocation> A, sp<Allocation> B, double beta, sp<Allocation> C) {
+                                 const sp<Allocation>& A, const sp<Allocation>& B, double beta, const sp<Allocation>& C) {
     validateHER2K(mRS, Element::F64_2(mRS), Trans, A, B, C);
     int k = 0;
     if (Trans == RsBlasNoTrans) {
@@ -1828,8 +1828,8 @@
 
 
 
-void ScriptIntrinsicBLAS::BNNM(sp<Allocation> A, int a_offset, sp<Allocation> B, int b_offset,
-                               sp<Allocation> C, int c_offset, int c_mult) {
+void ScriptIntrinsicBLAS::BNNM(const sp<Allocation>& A, int a_offset, const sp<Allocation>& B, int b_offset,
+                               const sp<Allocation>& C, int c_offset, int c_mult) {
     validateL3(mRS, Element::U8(mRS), RsBlasNoTrans, RsBlasTrans, 0, A, B, C);
 
     if (a_offset < 0 || a_offset > 255) {
diff --git a/cpp/ScriptIntrinsics.cpp b/cpp/ScriptIntrinsics.cpp
index 38224e6..b1a6dcf 100644
--- a/cpp/ScriptIntrinsics.cpp
+++ b/cpp/ScriptIntrinsics.cpp
@@ -33,7 +33,7 @@
 
 }
 
-sp<ScriptIntrinsic3DLUT> ScriptIntrinsic3DLUT::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsic3DLUT> ScriptIntrinsic3DLUT::create(const sp<RS>& rs, const sp<const Element>& e) {
     if (e->isCompatible(Element::U8_4(rs)) == false) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Element not supported for intrinsic");
         return nullptr;
@@ -45,7 +45,7 @@
     : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_3DLUT, e) {
 
 }
-void ScriptIntrinsic3DLUT::forEach(sp<Allocation> ain, sp<Allocation> aout) {
+void ScriptIntrinsic3DLUT::forEach(const sp<Allocation>& ain, const sp<Allocation>& aout) {
     if (ain->getType()->getElement()->isCompatible(mElement) == false ||
         aout->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "3DLUT forEach element mismatch");
@@ -53,7 +53,7 @@
     }
     Script::forEach(0, ain, aout, nullptr, 0);
 }
-void ScriptIntrinsic3DLUT::setLUT(sp<Allocation> lut) {
+void ScriptIntrinsic3DLUT::setLUT(const sp<Allocation>& lut) {
     sp<const Type> t = lut->getType();
     if (!t->getElement()->isCompatible(mElement)) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "setLUT element does not match");
@@ -67,7 +67,7 @@
     Script::setVar(0, lut);
 }
 
-sp<ScriptIntrinsicBlend> ScriptIntrinsicBlend::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicBlend> ScriptIntrinsicBlend::create(const sp<RS>& rs, const sp<const Element>& e) {
     if (e->isCompatible(Element::U8_4(rs)) == false) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Element not supported for intrinsic");
         return nullptr;
@@ -79,7 +79,7 @@
     : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_BLEND, e) {
 }
 
-void ScriptIntrinsicBlend::forEachClear(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachClear(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -87,7 +87,7 @@
     Script::forEach(0, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachSrc(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachSrc(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -95,7 +95,7 @@
     Script::forEach(1, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachDst(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachDst(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -103,7 +103,7 @@
     Script::forEach(2, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachSrcOver(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachSrcOver(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -111,7 +111,7 @@
     Script::forEach(3, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachDstOver(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachDstOver(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -119,7 +119,7 @@
     Script::forEach(4, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachSrcIn(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachSrcIn(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -127,7 +127,7 @@
     Script::forEach(5, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachDstIn(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachDstIn(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -135,7 +135,7 @@
     Script::forEach(6, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachSrcOut(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachSrcOut(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -143,7 +143,7 @@
     Script::forEach(7, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachDstOut(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachDstOut(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -151,7 +151,7 @@
     Script::forEach(8, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachSrcAtop(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachSrcAtop(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -159,7 +159,7 @@
     Script::forEach(9, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachDstAtop(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachDstAtop(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -167,7 +167,7 @@
     Script::forEach(10, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachXor(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachXor(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -175,7 +175,7 @@
     Script::forEach(11, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachMultiply(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachMultiply(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -183,7 +183,7 @@
     Script::forEach(14, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachAdd(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachAdd(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -191,7 +191,7 @@
     Script::forEach(34, in, out, nullptr, 0);
 }
 
-void ScriptIntrinsicBlend::forEachSubtract(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicBlend::forEachSubtract(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (in->getType()->getElement()->isCompatible(mElement) == false ||
         out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blend");
@@ -202,7 +202,7 @@
 
 
 
-sp<ScriptIntrinsicBlur> ScriptIntrinsicBlur::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicBlur> ScriptIntrinsicBlur::create(const sp<RS>& rs, const sp<const Element>& e) {
     if ((e->isCompatible(Element::U8_4(rs)) == false) &&
         (e->isCompatible(Element::U8(rs)) == false)) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blur");
@@ -216,7 +216,7 @@
 
 }
 
-void ScriptIntrinsicBlur::setInput(sp<Allocation> in) {
+void ScriptIntrinsicBlur::setInput(const sp<Allocation>& in) {
     if (in->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blur input");
         return;
@@ -224,7 +224,7 @@
     Script::setVar(1, in);
 }
 
-void ScriptIntrinsicBlur::forEach(sp<Allocation> out) {
+void ScriptIntrinsicBlur::forEach(const sp<Allocation>& out) {
     if (out->getType()->getElement()->isCompatible(mElement) == false) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element in blur output");
         return;
@@ -242,7 +242,7 @@
 
 
 
-sp<ScriptIntrinsicColorMatrix> ScriptIntrinsicColorMatrix::create(sp<RS> rs) {
+sp<ScriptIntrinsicColorMatrix> ScriptIntrinsicColorMatrix::create(const sp<RS>& rs) {
     return new ScriptIntrinsicColorMatrix(rs, Element::RGBA_8888(rs));
 }
 
@@ -253,7 +253,7 @@
 
 }
 
-void ScriptIntrinsicColorMatrix::forEach(sp<Allocation> in, sp<Allocation> out) {
+void ScriptIntrinsicColorMatrix::forEach(const sp<Allocation>& in, const sp<Allocation>& out) {
     if (!(in->getType()->getElement()->isCompatible(Element::U8(mRS))) &&
         !(in->getType()->getElement()->isCompatible(Element::U8_2(mRS))) &&
         !(in->getType()->getElement()->isCompatible(Element::U8_3(mRS))) &&
@@ -335,7 +335,7 @@
 
 
 
-sp<ScriptIntrinsicConvolve3x3> ScriptIntrinsicConvolve3x3::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicConvolve3x3> ScriptIntrinsicConvolve3x3::create(const sp<RS>& rs, const sp<const Element>& e) {
     if (!(e->isCompatible(Element::U8(rs))) &&
         !(e->isCompatible(Element::U8_2(rs))) &&
         !(e->isCompatible(Element::U8_3(rs))) &&
@@ -356,7 +356,7 @@
 
 }
 
-void ScriptIntrinsicConvolve3x3::setInput(sp<Allocation> in) {
+void ScriptIntrinsicConvolve3x3::setInput(const sp<Allocation>& in) {
     if (!(in->getType()->getElement()->isCompatible(mElement))) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Element mismatch in Convolve3x3");
         return;
@@ -364,7 +364,7 @@
     Script::setVar(1, in);
 }
 
-void ScriptIntrinsicConvolve3x3::forEach(sp<Allocation> out) {
+void ScriptIntrinsicConvolve3x3::forEach(const sp<Allocation>& out) {
     if (!(out->getType()->getElement()->isCompatible(mElement))) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Element mismatch in Convolve3x3");
         return;
@@ -376,7 +376,7 @@
     Script::setVar(0, (void*)v, sizeof(float) * 9);
 }
 
-sp<ScriptIntrinsicConvolve5x5> ScriptIntrinsicConvolve5x5::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicConvolve5x5> ScriptIntrinsicConvolve5x5::create(const sp<RS>& rs, const sp<const Element>& e) {
     if (!(e->isCompatible(Element::U8(rs))) &&
         !(e->isCompatible(Element::U8_2(rs))) &&
         !(e->isCompatible(Element::U8_3(rs))) &&
@@ -397,7 +397,7 @@
 
 }
 
-void ScriptIntrinsicConvolve5x5::setInput(sp<Allocation> in) {
+void ScriptIntrinsicConvolve5x5::setInput(const sp<Allocation>& in) {
     if (!(in->getType()->getElement()->isCompatible(mElement))) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Element mismatch in Convolve5x5 input");
         return;
@@ -405,7 +405,7 @@
     Script::setVar(1, in);
 }
 
-void ScriptIntrinsicConvolve5x5::forEach(sp<Allocation> out) {
+void ScriptIntrinsicConvolve5x5::forEach(const sp<Allocation>& out) {
     if (!(out->getType()->getElement()->isCompatible(mElement))) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Element mismatch in Convolve5x5 output");
         return;
@@ -418,7 +418,7 @@
     Script::setVar(0, (void*)v, sizeof(float) * 25);
 }
 
-sp<ScriptIntrinsicHistogram> ScriptIntrinsicHistogram::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicHistogram> ScriptIntrinsicHistogram::create(const sp<RS>& rs, const sp<const Element>& e) {
     return new ScriptIntrinsicHistogram(rs, e);
 }
 
@@ -427,7 +427,7 @@
 
 }
 
-void ScriptIntrinsicHistogram::setOutput(sp<Allocation> out) {
+void ScriptIntrinsicHistogram::setOutput(const sp<Allocation>& out) {
     if (!(out->getType()->getElement()->isCompatible(Element::U32(mRS))) &&
         !(out->getType()->getElement()->isCompatible(Element::U32_2(mRS))) &&
         !(out->getType()->getElement()->isCompatible(Element::U32_3(mRS))) &&
@@ -467,7 +467,7 @@
 
 }
 
-void ScriptIntrinsicHistogram::forEach(sp<Allocation> ain) {
+void ScriptIntrinsicHistogram::forEach(const sp<Allocation>& ain) {
     if (ain->getType()->getElement()->getVectorSize() <
         mOut->getType()->getElement()->getVectorSize()) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER,
@@ -486,7 +486,7 @@
 }
 
 
-void ScriptIntrinsicHistogram::forEach_dot(sp<Allocation> ain) {
+void ScriptIntrinsicHistogram::forEach_dot(const sp<Allocation>& ain) {
     if (mOut->getType()->getElement()->getVectorSize() != 1) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER,
                         "Output Histogram allocation must have vector size of 1 " \
@@ -503,7 +503,7 @@
     Script::forEach(1, ain, nullptr, nullptr, 0);
 }
 
-sp<ScriptIntrinsicLUT> ScriptIntrinsicLUT::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicLUT> ScriptIntrinsicLUT::create(const sp<RS>& rs, const sp<const Element>& e) {
     if (!(e->isCompatible(Element::U8_4(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for LUT");
         return nullptr;
@@ -523,7 +523,7 @@
     setVar(0, LUT);
 }
 
-void ScriptIntrinsicLUT::forEach(sp<Allocation> ain, sp<Allocation> aout) {
+void ScriptIntrinsicLUT::forEach(const sp<Allocation>& ain, const sp<Allocation>& aout) {
     if (mDirty) {
         LUT->copy1DFrom((void*)mCache);
         mDirty = false;
@@ -568,7 +568,7 @@
 
 }
 
-sp<ScriptIntrinsicResize> ScriptIntrinsicResize::create(sp<RS> rs) {
+sp<ScriptIntrinsicResize> ScriptIntrinsicResize::create(const sp<RS>& rs) {
     return new ScriptIntrinsicResize(rs, nullptr);
 }
 
@@ -576,7 +576,7 @@
     : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_RESIZE, e) {
 
 }
-void ScriptIntrinsicResize::forEach_bicubic(sp<Allocation> aout) {
+void ScriptIntrinsicResize::forEach_bicubic(const sp<Allocation>& aout) {
     if (aout == mInput) {
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Resize Input and Ouput cannot be the same");
     }
@@ -587,7 +587,7 @@
     }
     Script::forEach(0, nullptr, aout, nullptr, 0);
 }
-void ScriptIntrinsicResize::setInput(sp<Allocation> ain) {
+void ScriptIntrinsicResize::setInput(const sp<Allocation>& ain) {
     if (!(ain->getType()->getElement()->isCompatible(Element::U8(mRS))) &&
         !(ain->getType()->getElement()->isCompatible(Element::U8_2(mRS))) &&
         !(ain->getType()->getElement()->isCompatible(Element::U8_3(mRS))) &&
@@ -605,7 +605,7 @@
 }
 
 
-sp<ScriptIntrinsicYuvToRGB> ScriptIntrinsicYuvToRGB::create(sp<RS> rs, sp<const Element> e) {
+sp<ScriptIntrinsicYuvToRGB> ScriptIntrinsicYuvToRGB::create(const sp<RS>& rs, const sp<const Element>& e) {
     if (!(e->isCompatible(Element::U8_4(rs)))) {
         rs->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for YuvToRGB");
         return nullptr;
@@ -618,7 +618,7 @@
 
 }
 
-void ScriptIntrinsicYuvToRGB::setInput(sp<Allocation> in) {
+void ScriptIntrinsicYuvToRGB::setInput(const sp<Allocation>& in) {
     if (!(in->getType()->getElement()->isCompatible(Element::YUV(mRS)))) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for input in YuvToRGB");
         return;
@@ -626,7 +626,7 @@
     Script::setVar(0, in);
 }
 
-void ScriptIntrinsicYuvToRGB::forEach(sp<Allocation> out) {
+void ScriptIntrinsicYuvToRGB::forEach(const sp<Allocation>& out) {
     if (!(out->getType()->getElement()->isCompatible(mElement))) {
         mRS->throwError(RS_ERROR_INVALID_ELEMENT, "Invalid element for output in YuvToRGB");
         return;
diff --git a/cpp/Type.cpp b/cpp/Type.cpp
index 784553b..70bbe4c 100644
--- a/cpp/Type.cpp
+++ b/cpp/Type.cpp
@@ -107,7 +107,7 @@
     calcElementCount();
 }
 
-sp<const Type> Type::create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ) {
+sp<const Type> Type::create(const sp<RS>& rs, const sp<const Element>& e, uint32_t dimX, uint32_t dimY, uint32_t dimZ) {
     void * id = RS::dispatch->TypeCreate(rs->getContext(), e->getID(), dimX, dimY, dimZ, false, false, 0);
     Type *t = new Type(id, rs);
 
diff --git a/cpp/rsCppStructs.h b/cpp/rsCppStructs.h
index a3e65ab..9b703a4 100644
--- a/cpp/rsCppStructs.h
+++ b/cpp/rsCppStructs.h
@@ -541,7 +541,7 @@
     void * getID() const;
     virtual ~BaseObj();
     virtual void updateFromNative();
-    virtual bool equals(sp<const BaseObj> obj);
+    virtual bool equals(const sp<const BaseObj>& obj);
 
 protected:
     void *mID;
@@ -551,7 +551,7 @@
     BaseObj(void *id, sp<RS> rs);
     void checkValid();
 
-    static void * getObjID(sp<const BaseObj> o);
+    static void * getObjID(const sp<const BaseObj>& o);
 
 };
 
@@ -594,7 +594,7 @@
     uint32_t mCurrentCount;
 
     void * getIDSafe() const;
-    void updateCacheInfo(sp<const Type> t);
+    void updateCacheInfo(const sp<const Type>& t);
 
     Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
 
@@ -664,7 +664,7 @@
      * operation is only valid for Allocations with USAGE_IO_OUTPUT.
      * @param[in] s Surface to associate with allocation
      */
-    void setSurface(sp<Surface> s);
+    void setSurface(const sp<Surface>& s);
 #endif
 
     /**
@@ -691,7 +691,7 @@
      * @param[in] data Allocation from which to copy
      * @param[in] dataOff offset of first Element in data to copy
      */
-    void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
+    void copy1DRangeFrom(uint32_t off, size_t count, const sp<const Allocation>& data, uint32_t dataOff);
 
     /**
      * Copy an array into part of this Allocation.
@@ -748,7 +748,7 @@
      * @param[in] dataYoff Y offset of region to copy from in data
      */
     void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
-                         sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
+                         const sp<const Allocation>& data, uint32_t dataXoff, uint32_t dataYoff);
 
     /**
      * Copy from a strided array into a rectangular region in this Allocation.
@@ -818,7 +818,7 @@
      */
     void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
                          uint32_t w, uint32_t h, uint32_t d,
-                         sp<const Allocation> data,
+                         const sp<const Allocation>& data,
                          uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
 
     /**
@@ -843,7 +843,7 @@
      * @param[in] usage usage for the Allocation
      * @return new Allocation
      */
-    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
+    static sp<Allocation> createTyped(const sp<RS>& rs, const sp<const Type>& type,
                                    RsAllocationMipmapControl mipmaps, uint32_t usage);
 
     /**
@@ -856,7 +856,7 @@
      * @param[in] pointer existing backing store to use for this Allocation if possible
      * @return new Allocation
      */
-    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
+    static sp<Allocation> createTyped(const sp<RS>& rs, const sp<const Type>& type,
                                    RsAllocationMipmapControl mipmaps, uint32_t usage, void * pointer);
 
     /**
@@ -866,7 +866,7 @@
      * @param[in] usage usage for the Allocation
      * @return new Allocation
      */
-    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
+    static sp<Allocation> createTyped(const sp<RS>& rs, const sp<const Type>& type,
                                    uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
     /**
      * Creates an Allocation with a specified number of given elements.
@@ -876,7 +876,7 @@
      * @param[in] usage usage for the Allocation
      * @return new Allocation
      */
-    static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
+    static sp<Allocation> createSized(const sp<RS>& rs, const sp<const Element>& e, size_t count,
                                    uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
 
     /**
@@ -888,7 +888,7 @@
      * @param[in] usage usage for the Allocation
      * @return new Allocation
      */
-    static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
+    static sp<Allocation> createSized2D(const sp<RS>& rs, const sp<const Element>& e,
                                         size_t x, size_t y,
                                         uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
 
@@ -1004,363 +1004,363 @@
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> BOOLEAN(sp<RS> rs);
+    static sp<const Element> BOOLEAN(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single unsigned char.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U8(sp<RS> rs);
+    static sp<const Element> U8(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single signed char.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I8(sp<RS> rs);
+    static sp<const Element> I8(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single unsigned short.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U16(sp<RS> rs);
+    static sp<const Element> U16(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single signed short.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I16(sp<RS> rs);
+    static sp<const Element> I16(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single unsigned int.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U32(sp<RS> rs);
+    static sp<const Element> U32(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single signed int.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I32(sp<RS> rs);
+    static sp<const Element> I32(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single unsigned long long.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U64(sp<RS> rs);
+    static sp<const Element> U64(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single signed long long.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I64(sp<RS> rs);
+    static sp<const Element> I64(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single half.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F16(sp<RS> rs);
+    static sp<const Element> F16(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single float.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F32(sp<RS> rs);
+    static sp<const Element> F32(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single double.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F64(sp<RS> rs);
+    static sp<const Element> F64(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single Element.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> ELEMENT(sp<RS> rs);
+    static sp<const Element> ELEMENT(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single Type.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> TYPE(sp<RS> rs);
+    static sp<const Element> TYPE(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single Allocation.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> ALLOCATION(sp<RS> rs);
+    static sp<const Element> ALLOCATION(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single Sampler.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> SAMPLER(sp<RS> rs);
+    static sp<const Element> SAMPLER(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a single Script.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> SCRIPT(sp<RS> rs);
+    static sp<const Element> SCRIPT(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an ALPHA_8 pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> A_8(sp<RS> rs);
+    static sp<const Element> A_8(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an RGB_565 pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> RGB_565(sp<RS> rs);
+    static sp<const Element> RGB_565(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an RGB_888 pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> RGB_888(sp<RS> rs);
+    static sp<const Element> RGB_888(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an RGBA_5551 pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> RGBA_5551(sp<RS> rs);
+    static sp<const Element> RGBA_5551(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an RGBA_4444 pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> RGBA_4444(sp<RS> rs);
+    static sp<const Element> RGBA_4444(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an RGBA_8888 pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> RGBA_8888(sp<RS> rs);
+    static sp<const Element> RGBA_8888(const sp<RS> &rs);
 
     /**
      * Utility function for returning an Element containing a half2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F16_2(sp<RS> rs);
+    static sp<const Element> F16_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a half3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F16_3(sp<RS> rs);
+    static sp<const Element> F16_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a half4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F16_4(sp<RS> rs);
+    static sp<const Element> F16_4(const sp<RS> &rs);
 
     /**
      * Utility function for returning an Element containing a float2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F32_2(sp<RS> rs);
+    static sp<const Element> F32_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a float3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F32_3(sp<RS> rs);
+    static sp<const Element> F32_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a float4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F32_4(sp<RS> rs);
+    static sp<const Element> F32_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a double2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F64_2(sp<RS> rs);
+    static sp<const Element> F64_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a double3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F64_3(sp<RS> rs);
+    static sp<const Element> F64_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a double4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> F64_4(sp<RS> rs);
+    static sp<const Element> F64_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a uchar2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U8_2(sp<RS> rs);
+    static sp<const Element> U8_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a uchar3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U8_3(sp<RS> rs);
+    static sp<const Element> U8_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a uchar4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U8_4(sp<RS> rs);
+    static sp<const Element> U8_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a char2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I8_2(sp<RS> rs);
+    static sp<const Element> I8_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a char3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I8_3(sp<RS> rs);
+    static sp<const Element> I8_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a char4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I8_4(sp<RS> rs);
+    static sp<const Element> I8_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a ushort2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U16_2(sp<RS> rs);
+    static sp<const Element> U16_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a ushort3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U16_3(sp<RS> rs);
+    static sp<const Element> U16_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a ushort4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U16_4(sp<RS> rs);
+    static sp<const Element> U16_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a short2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I16_2(sp<RS> rs);
+    static sp<const Element> I16_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a short3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I16_3(sp<RS> rs);
+    static sp<const Element> I16_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a short4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I16_4(sp<RS> rs);
+    static sp<const Element> I16_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a uint2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U32_2(sp<RS> rs);
+    static sp<const Element> U32_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a uint3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U32_3(sp<RS> rs);
+    static sp<const Element> U32_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a uint4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U32_4(sp<RS> rs);
+    static sp<const Element> U32_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an int2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I32_2(sp<RS> rs);
+    static sp<const Element> I32_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an int3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I32_3(sp<RS> rs);
+    static sp<const Element> I32_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an int4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I32_4(sp<RS> rs);
+    static sp<const Element> I32_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a ulong2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U64_2(sp<RS> rs);
+    static sp<const Element> U64_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a ulong3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U64_3(sp<RS> rs);
+    static sp<const Element> U64_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a ulong4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> U64_4(sp<RS> rs);
+    static sp<const Element> U64_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a long2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I64_2(sp<RS> rs);
+    static sp<const Element> I64_2(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a long3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I64_3(sp<RS> rs);
+    static sp<const Element> I64_3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a long4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> I64_4(sp<RS> rs);
+    static sp<const Element> I64_4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing a YUV pixel.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> YUV(sp<RS> rs);
+    static sp<const Element> YUV(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an rs_matrix_4x4.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> MATRIX_4X4(sp<RS> rs);
+    static sp<const Element> MATRIX_4X4(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an rs_matrix_3x3.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> MATRIX_3X3(sp<RS> rs);
+    static sp<const Element> MATRIX_3X3(const sp<RS> &rs);
     /**
      * Utility function for returning an Element containing an rs_matrix_2x2.
      * @param[in] rs RenderScript context
      * @return Element
      */
-    static sp<const Element> MATRIX_2X2(sp<RS> rs);
+    static sp<const Element> MATRIX_2X2(const sp<RS> &rs);
 
     void updateFromNative();
 
@@ -1370,7 +1370,7 @@
      * @param[in] dt data type
      * @return Element
      */
-    static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
+    static sp<const Element> createUser(const sp<RS>& rs, RsDataType dt);
     /**
      * Create a vector Element with the given DataType
      * @param[in] rs RenderScript
@@ -1378,7 +1378,7 @@
      * @param[in] size vector size
      * @return Element
      */
-    static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
+    static sp<const Element> createVector(const sp<RS>& rs, RsDataType dt, uint32_t size);
     /**
      * Create an Element with a given DataType and DataKind.
      * @param[in] rs RenderScript context
@@ -1386,14 +1386,14 @@
      * @param[in] dk DataKind
      * @return Element
      */
-    static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
+    static sp<const Element> createPixel(const sp<RS>& rs, RsDataType dt, RsDataKind dk);
 
     /**
      * Returns true if the Element can interoperate with this Element.
      * @param[in] e Element to compare
      * @return true if Elements can interoperate
      */
-    bool isCompatible(sp<const Element>e) const;
+    bool isCompatible(const sp<const Element>&e) const;
 
     /**
      * Builder class for producing complex elements with matching field and name
@@ -1414,7 +1414,7 @@
     public:
         explicit Builder(sp<RS> rs);
         ~Builder();
-        void add(sp<const Element> e, const char * name, uint32_t arraySize = 1);
+        void add(const sp<const Element>& e, const char * name, uint32_t arraySize = 1);
         sp<const Element> create();
     };
 
@@ -1536,7 +1536,7 @@
       }
     */
 
-    void add(sp<BaseObj> obj) {
+    void add(const sp<BaseObj>& obj) {
         if (obj != NULL) {
             add((uint32_t) (uintptr_t) obj->getID());
         } else {
@@ -1663,7 +1663,7 @@
      * @param[in] dimZ Z dimension
      * @return new Type
      */
-    static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
+    static sp<const Type> create(const sp<RS>& rs, const sp<const Element>& e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
 
     class Builder {
     protected:
@@ -1698,11 +1698,11 @@
 
 protected:
     Script(void *id, sp<RS> rs);
-    void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
+    void forEach(uint32_t slot, const sp<const Allocation>& in, const sp<const Allocation>& out,
             const void *v, size_t) const;
-    void bindAllocation(sp<Allocation> va, uint32_t slot) const;
+    void bindAllocation(const sp<Allocation>& va, uint32_t slot) const;
     void setVar(uint32_t index, const void *, size_t len) const;
-    void setVar(uint32_t index, sp<const BaseObj> o) const;
+    void setVar(uint32_t index, const sp<const BaseObj>& o) const;
     void invoke(uint32_t slot, const void *v, size_t len) const;
 
 
@@ -1734,7 +1734,7 @@
         sp<const Element> mElement;
         sp<Allocation> mAllocation;
 
-        void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
+        void init(const sp<RS>& rs, uint32_t dimx, uint32_t usages = 0);
 
     public:
         sp<const Element> getElement() {
@@ -1792,21 +1792,21 @@
      * @param[in] e Element
      * @return new ScriptIntrinsic
      */
-    static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsic3DLUT> create(const sp<RS>& rs, const sp<const Element>& e);
 
     /**
      * Launch the intrinsic.
      * @param[in] ain input Allocation
      * @param[in] aout output Allocation
      */
-    void forEach(sp<Allocation> ain, sp<Allocation> aout);
+    void forEach(const sp<Allocation>& ain, const sp<Allocation>& aout);
 
     /**
      * Sets the lookup table. The lookup table must use the same Element as the
      * intrinsic.
      * @param[in] lut new lookup table
      */
-    void setLUT(sp<Allocation> lut);
+    void setLUT(const sp<Allocation>& lut);
 };
 
 
@@ -1829,7 +1829,7 @@
      * @param rs The RenderScript context
      * @return ScriptIntrinsicBLAS
      */
-    static sp<ScriptIntrinsicBLAS> create(sp<RS> rs);
+    static sp<ScriptIntrinsicBLAS> create(const sp<RS>& rs);
 
     /**
      * SGEMV performs one of the matrix-vector operations
@@ -1847,8 +1847,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void SGEMV(RsBlasTranspose TransA,
-               float alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               float beta, sp<Allocation> Y, int incY);
+               float alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               float beta, const sp<Allocation>& Y, int incY);
 
     /**
      * DGEMV performs one of the matrix-vector operations
@@ -1866,8 +1866,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void DGEMV(RsBlasTranspose TransA,
-               double alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               double beta, sp<Allocation> Y, int incY);
+               double alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               double beta, const sp<Allocation>& Y, int incY);
 
     /**
      * CGEMV performs one of the matrix-vector operations
@@ -1885,8 +1885,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void CGEMV(RsBlasTranspose TransA,
-               Float2 alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               Float2 beta, sp<Allocation> Y, int incY);
+               Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               Float2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * ZGEMV performs one of the matrix-vector operations
@@ -1904,8 +1904,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void ZGEMV(RsBlasTranspose TransA,
-               Double2 alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               Double2 beta, sp<Allocation> Y, int incY);
+               Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               Double2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * SGBMV performs one of the matrix-vector operations
@@ -1932,8 +1932,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void SGBMV(RsBlasTranspose TransA,
-               int KL, int KU, float alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               float beta, sp<Allocation> Y, int incY);
+               int KL, int KU, float alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               float beta, const sp<Allocation>& Y, int incY);
 
     /**
      * DGBMV performs one of the matrix-vector operations
@@ -1960,8 +1960,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void DGBMV(RsBlasTranspose TransA,
-               int KL, int KU, double alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, double beta, sp<Allocation> Y, int incY);
+               int KL, int KU, double alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, double beta, const sp<Allocation>& Y, int incY);
 
     /**
      * CGBMV performs one of the matrix-vector operations
@@ -1988,8 +1988,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void CGBMV(RsBlasTranspose TransA,
-               int KL, int KU, Float2 alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, Float2 beta, sp<Allocation> Y, int incY);
+               int KL, int KU, Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, Float2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * ZGBMV performs one of the matrix-vector operations
@@ -2016,8 +2016,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
     void ZGBMV(RsBlasTranspose TransA,
-               int KL, int KU, Double2 alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               Double2 beta, sp<Allocation> Y, int incY);
+               int KL, int KU, Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               Double2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * STRMV performs one of the matrix-vector operations
@@ -2033,7 +2033,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void STRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * DTRMV performs one of the matrix-vector operations
@@ -2049,7 +2049,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void DTRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * CTRMV performs one of the matrix-vector operations
@@ -2065,7 +2065,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void CTRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * ZTRMV performs one of the matrix-vector operations
@@ -2081,7 +2081,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void ZTRMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * STBMV performs one of the matrix-vector operations
@@ -2105,7 +2105,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void STBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * DTBMV performs one of the matrix-vector operations
@@ -2129,7 +2129,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void DTBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * CTBMV performs one of the matrix-vector operations
@@ -2153,7 +2153,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void CTBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * ZTBMV performs one of the matrix-vector operations
@@ -2177,7 +2177,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void ZTBMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * STPMV performs one of the matrix-vector operations
@@ -2201,7 +2201,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void STPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * DTPMV performs one of the matrix-vector operations
@@ -2225,7 +2225,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void DTPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * CTPMV performs one of the matrix-vector operations
@@ -2249,7 +2249,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void CTPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * ZTPMV performs one of the matrix-vector operations
@@ -2273,7 +2273,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void ZTPMV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * STRSV solves one of the systems of equations
@@ -2289,7 +2289,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void STRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * DTRSV solves one of the systems of equations
@@ -2305,7 +2305,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void DTRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * CTRSV solves one of the systems of equations
@@ -2321,7 +2321,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void CTRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * ZTRSV solves one of the systems of equations
@@ -2337,7 +2337,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void ZTRSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> A, sp<Allocation> X, int incX);
+               const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * STBSV solves one of the systems of equations
@@ -2361,7 +2361,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void STBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * DTBSV solves one of the systems of equations
@@ -2385,7 +2385,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void DTBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * CTBSV solves one of the systems of equations
@@ -2409,7 +2409,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void CTBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * ZTBSV solves one of the systems of equations
@@ -2433,7 +2433,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void ZTBSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               int K, sp<Allocation> A, sp<Allocation> X, int incX);
+               int K, const sp<Allocation>& A, const sp<Allocation>& X, int incX);
 
     /**
      * STPSV solves one of the systems of equations
@@ -2457,7 +2457,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void STPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * DTPSV solves one of the systems of equations
@@ -2481,7 +2481,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void DTPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * CTPSV solves one of the systems of equations
@@ -2505,7 +2505,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void CTPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * ZTPSV solves one of the systems of equations
@@ -2529,7 +2529,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      */
     void ZTPSV(RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               sp<Allocation> Ap, sp<Allocation> X, int incX);
+               const sp<Allocation>& Ap, const sp<Allocation>& X, int incX);
 
     /**
      * SSYMV performs the matrix-vector operation
@@ -2546,8 +2546,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F32}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void SSYMV(RsBlasUplo Uplo, float alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, float beta, sp<Allocation> Y, int incY);
+    void SSYMV(RsBlasUplo Uplo, float alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, float beta, const sp<Allocation>& Y, int incY);
 
     /**
      * SSBMV performs the matrix-vector operation
@@ -2572,8 +2572,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F32}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void SSBMV(RsBlasUplo Uplo, int K, float alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, float beta, sp<Allocation> Y, int incY);
+    void SSBMV(RsBlasUplo Uplo, int K, float alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, float beta, const sp<Allocation>& Y, int incY);
 
     /**
      * SSPMV performs the matrix-vector operation
@@ -2598,8 +2598,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F32}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void SSPMV(RsBlasUplo Uplo, float alpha, sp<Allocation> Ap, sp<Allocation> X,
-               int incX, float beta, sp<Allocation> Y, int incY);
+    void SSPMV(RsBlasUplo Uplo, float alpha, const sp<Allocation>& Ap, const sp<Allocation>& X,
+               int incX, float beta, const sp<Allocation>& Y, int incY);
 
     /**
      * SGER performs the rank 1 operation
@@ -2614,7 +2614,7 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32}.
      */
-    void SGER(float alpha, sp<Allocation> X, int incX, sp<Allocation> Y, int incY, sp<Allocation> A);
+    void SGER(float alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * SSYR performs the rank 1 operation
@@ -2628,7 +2628,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32}.
      */
-    void SSYR(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX, sp<Allocation> A);
+    void SSYR(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& A);
 
     /**
      * SSPR performs the rank 1 operation
@@ -2650,7 +2650,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F32}.
      */
-    void SSPR(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX, sp<Allocation> Ap);
+    void SSPR(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Ap);
 
     /**
      * SSYR2 performs the symmetric rank 2 operation
@@ -2666,8 +2666,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32}.
      */
-    void SSYR2(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void SSYR2(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * SSPR2 performs the symmetric rank 2 operation
@@ -2691,8 +2691,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F32}.
      */
-    void SSPR2(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> Ap);
+    void SSPR2(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap);
 
     /**
      * DSYMV performs the matrix-vector operation
@@ -2709,8 +2709,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F64}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void DSYMV(RsBlasUplo Uplo, double alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               double beta, sp<Allocation> Y, int incY);
+    void DSYMV(RsBlasUplo Uplo, double alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               double beta, const sp<Allocation>& Y, int incY);
 
     /**
      * DSBMV performs the matrix-vector operation
@@ -2735,8 +2735,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F64}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void DSBMV(RsBlasUplo Uplo, int K, double alpha, sp<Allocation> A, sp<Allocation> X, int incX,
-               double beta, sp<Allocation> Y, int incY);
+    void DSBMV(RsBlasUplo Uplo, int K, double alpha, const sp<Allocation>& A, const sp<Allocation>& X, int incX,
+               double beta, const sp<Allocation>& Y, int incY);
 
     /**
      * DSPMV performs the matrix-vector operation
@@ -2761,8 +2761,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F64}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void DSPMV(RsBlasUplo Uplo, double alpha, sp<Allocation> Ap, sp<Allocation> X, int incX,
-               double beta, sp<Allocation> Y, int incY);
+    void DSPMV(RsBlasUplo Uplo, double alpha, const sp<Allocation>& Ap, const sp<Allocation>& X, int incX,
+               double beta, const sp<Allocation>& Y, int incY);
 
     /**
      * DGER performs the rank 1 operation
@@ -2777,7 +2777,7 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64}.
      */
-    void DGER(double alpha, sp<Allocation> X, int incX, sp<Allocation> Y, int incY, sp<Allocation> A);
+    void DGER(double alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * DSYR performs the rank 1 operation
@@ -2791,7 +2791,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64}.
      */
-    void DSYR(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX, sp<Allocation> A);
+    void DSYR(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& A);
 
     /**
      * DSPR performs the rank 1 operation
@@ -2813,7 +2813,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F64}.
      */
-    void DSPR(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX, sp<Allocation> Ap);
+    void DSPR(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Ap);
 
     /**
      * DSYR2 performs the symmetric rank 2 operation
@@ -2829,8 +2829,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64}.
      */
-    void DSYR2(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void DSYR2(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * DSPR2 performs the symmetric rank 2 operation
@@ -2854,8 +2854,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F64}.
      */
-    void DSPR2(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> Ap);
+    void DSPR2(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap);
 
     /**
      * CHEMV performs the matrix-vector operation
@@ -2872,8 +2872,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F32_2}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void CHEMV(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, Float2 beta, sp<Allocation> Y, int incY);
+    void CHEMV(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, Float2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * CHBMV performs the matrix-vector operation
@@ -2898,8 +2898,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F32_2}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void CHBMV(RsBlasUplo Uplo, int K, Float2 alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, Float2 beta, sp<Allocation> Y, int incY);
+    void CHBMV(RsBlasUplo Uplo, int K, Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, Float2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * CHPMV performs the matrix-vector operation
@@ -2924,8 +2924,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F32_2}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void CHPMV(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> Ap, sp<Allocation> X,
-               int incX, Float2 beta, sp<Allocation> Y, int incY);
+    void CHPMV(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& Ap, const sp<Allocation>& X,
+               int incX, Float2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * CGERU performs the rank 1 operation
@@ -2940,8 +2940,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32_2}.
      */
-    void CGERU(Float2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void CGERU(Float2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * CGERC performs the rank 1 operation
@@ -2956,8 +2956,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32_2}.
      */
-    void CGERC(Float2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void CGERC(Float2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * CHER performs the rank 1 operation
@@ -2971,7 +2971,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32_2}.
      */
-    void CHER(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX, sp<Allocation> A);
+    void CHER(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& A);
 
     /**
      * CHPR performs the rank 1 operation
@@ -2993,7 +2993,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F32_2}.
      */
-    void CHPR(RsBlasUplo Uplo, float alpha, sp<Allocation> X, int incX, sp<Allocation> Ap);
+    void CHPR(RsBlasUplo Uplo, float alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Ap);
 
     /**
      * CHER2 performs the symmetric rank 2 operation
@@ -3009,8 +3009,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F32_2}.
      */
-    void CHER2(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void CHER2(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * CHPR2 performs the symmetric rank 2 operation
@@ -3034,8 +3034,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F32_2}.
      */
-    void CHPR2(RsBlasUplo Uplo, Float2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> Ap);
+    void CHPR2(RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap);
 
     /**
      * ZHEMV performs the matrix-vector operation
@@ -3052,8 +3052,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F64_2}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void ZHEMV(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, Double2 beta, sp<Allocation> Y, int incY);
+    void ZHEMV(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, Double2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * ZHBMV performs the matrix-vector operation
@@ -3078,8 +3078,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F64_2}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void ZHBMV(RsBlasUplo Uplo, int K, Double2 alpha, sp<Allocation> A, sp<Allocation> X,
-               int incX, Double2 beta, sp<Allocation> Y, int incY);
+    void ZHBMV(RsBlasUplo Uplo, int K, Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& X,
+               int incX, Double2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * ZHPMV performs the matrix-vector operation
@@ -3104,8 +3104,8 @@
      * @param Y The input allocation contains vector y, supported elements type: {Element#F64_2}.
      * @param incY The increment for the elements of vector y, must be larger than zero.
      */
-    void ZHPMV(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> Ap, sp<Allocation> X,
-               int incX, Double2 beta, sp<Allocation> Y, int incY);
+    void ZHPMV(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& Ap, const sp<Allocation>& X,
+               int incX, Double2 beta, const sp<Allocation>& Y, int incY);
 
     /**
      * ZGERU performs the rank 1 operation
@@ -3120,8 +3120,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64_2}.
      */
-    void ZGERU(Double2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void ZGERU(Double2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * ZGERC performs the rank 1 operation
@@ -3136,8 +3136,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64_2}.
      */
-    void ZGERC(Double2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void ZGERC(Double2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * ZHER performs the rank 1 operation
@@ -3151,7 +3151,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64_2}.
      */
-    void ZHER(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX, sp<Allocation> A);
+    void ZHER(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& A);
 
     /**
      * ZHPR performs the rank 1 operation
@@ -3173,7 +3173,7 @@
      * @param incX The increment for the elements of vector x, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F64_2}.
      */
-    void ZHPR(RsBlasUplo Uplo, double alpha, sp<Allocation> X, int incX, sp<Allocation> Ap);
+    void ZHPR(RsBlasUplo Uplo, double alpha, const sp<Allocation>& X, int incX, const sp<Allocation>& Ap);
 
     /**
      * ZHER2 performs the symmetric rank 2 operation
@@ -3189,8 +3189,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param A The input allocation contains matrix A, supported elements type: {Element#F64_2}.
      */
-    void ZHER2(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> A);
+    void ZHER2(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& A);
 
     /**
      * ZHPR2 performs the symmetric rank 2 operation
@@ -3214,8 +3214,8 @@
      * @param incY The increment for the elements of vector y, must be larger than zero.
      * @param Ap The input allocation contains matrix A, supported elements type: {Element#F64_2}.
      */
-    void ZHPR2(RsBlasUplo Uplo, Double2 alpha, sp<Allocation> X, int incX,
-               sp<Allocation> Y, int incY, sp<Allocation> Ap);
+    void ZHPR2(RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& X, int incX,
+               const sp<Allocation>& Y, int incY, const sp<Allocation>& Ap);
 
     /**
      * SGEMM performs one of the matrix-matrix operations
@@ -3231,8 +3231,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32}.
      */
-    void SGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, float alpha, sp<Allocation> A,
-                      sp<Allocation> B, float beta, sp<Allocation> C);
+    void SGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, float alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, float beta, const sp<Allocation>& C);
 
 
     /**
@@ -3249,8 +3249,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64}.
      */
-    void DGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, double alpha, sp<Allocation> A,
-                      sp<Allocation> B, double beta, sp<Allocation> C);
+    void DGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, double alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, double beta, const sp<Allocation>& C);
 
     /**
      * CGEMM performs one of the matrix-matrix operations
@@ -3266,8 +3266,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
-    void CGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, Float2 alpha, sp<Allocation> A,
-                      sp<Allocation> B, Float2 beta, sp<Allocation> C);
+    void CGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, Float2 alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C);
 
     /**
      * ZGEMM performs one of the matrix-matrix operations
@@ -3283,8 +3283,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2
      */
-    void ZGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, Double2 alpha, sp<Allocation> A,
-                      sp<Allocation> B, Double2 beta, sp<Allocation> C);
+    void ZGEMM(RsBlasTranspose TransA, RsBlasTranspose TransB, Double2 alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C);
 
     /**
      * SSYMM performs one of the matrix-matrix operations
@@ -3300,8 +3300,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32}.
      */
-    void SSYMM(RsBlasSide Side, RsBlasUplo Uplo, float alpha, sp<Allocation> A,
-                      sp<Allocation> B, float beta, sp<Allocation> C);
+    void SSYMM(RsBlasSide Side, RsBlasUplo Uplo, float alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, float beta, const sp<Allocation>& C);
 
     /**
      * DSYMM performs one of the matrix-matrix operations
@@ -3317,8 +3317,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64}.
      */
-    void DSYMM(RsBlasSide Side, RsBlasUplo Uplo, double alpha, sp<Allocation> A,
-                      sp<Allocation> B, double beta, sp<Allocation> C);
+    void DSYMM(RsBlasSide Side, RsBlasUplo Uplo, double alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, double beta, const sp<Allocation>& C);
 
     /**
      * CSYMM performs one of the matrix-matrix operations
@@ -3334,8 +3334,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
-    void CSYMM(RsBlasSide Side, RsBlasUplo Uplo, Float2 alpha, sp<Allocation> A,
-                      sp<Allocation> B, Float2 beta, sp<Allocation> C);
+    void CSYMM(RsBlasSide Side, RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C);
 
     /**
      * ZSYMM performs one of the matrix-matrix operations
@@ -3351,8 +3351,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2}.
      */
-    void ZSYMM(RsBlasSide Side, RsBlasUplo Uplo, Double2 alpha, sp<Allocation> A,
-                      sp<Allocation> B, Double2 beta, sp<Allocation> C);
+    void ZSYMM(RsBlasSide Side, RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& A,
+                      const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C);
 
     /**
      * SSYRK performs one of the symmetric rank k operations
@@ -3368,7 +3368,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32}.
      */
     void SSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha,
-               sp<Allocation> A, float beta, sp<Allocation> C);
+               const sp<Allocation>& A, float beta, const sp<Allocation>& C);
 
     /**
      * DSYRK performs one of the symmetric rank k operations
@@ -3384,7 +3384,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64}.
      */
     void DSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha,
-               sp<Allocation> A, double beta, sp<Allocation> C);
+               const sp<Allocation>& A, double beta, const sp<Allocation>& C);
 
     /**
      * CSYRK performs one of the symmetric rank k operations
@@ -3400,7 +3400,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
     void CSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha,
-               sp<Allocation> A, Float2 beta, sp<Allocation> C);
+               const sp<Allocation>& A, Float2 beta, const sp<Allocation>& C);
 
     /**
      * ZSYRK performs one of the symmetric rank k operations
@@ -3416,7 +3416,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2}.
      */
     void ZSYRK(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha,
-               sp<Allocation> A, Double2 beta, sp<Allocation> C);
+               const sp<Allocation>& A, Double2 beta, const sp<Allocation>& C);
 
     /**
      * SSYR2K performs one of the symmetric rank 2k operations
@@ -3433,7 +3433,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32}.
      */
     void SSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha,
-                sp<Allocation> A, sp<Allocation> B, float beta, sp<Allocation> C);
+                const sp<Allocation>& A, const sp<Allocation>& B, float beta, const sp<Allocation>& C);
 
     /**
      * DSYR2K performs one of the symmetric rank 2k operations
@@ -3450,7 +3450,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64}.
      */
     void DSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha,
-                sp<Allocation> A, sp<Allocation> B, double beta, sp<Allocation> C);
+                const sp<Allocation>& A, const sp<Allocation>& B, double beta, const sp<Allocation>& C);
 
     /**
      * CSYR2K performs one of the symmetric rank 2k operations
@@ -3467,7 +3467,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
     void CSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha,
-                sp<Allocation> A, sp<Allocation> B, Float2 beta, sp<Allocation> C);
+                const sp<Allocation>& A, const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C);
 
     /**
      * ZSYR2K performs one of the symmetric rank 2k operations
@@ -3484,7 +3484,7 @@
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2}.
      */
     void ZSYR2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha,
-                sp<Allocation> A, sp<Allocation> B, Double2 beta, sp<Allocation> C);
+                const sp<Allocation>& A, const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C);
 
     /**
      * STRMM performs one of the matrix-matrix operations
@@ -3502,7 +3502,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F32}.
      */
     void STRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA,
-               RsBlasDiag Diag, float alpha, sp<Allocation> A, sp<Allocation> B);
+               RsBlasDiag Diag, float alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * DTRMM performs one of the matrix-matrix operations
@@ -3520,7 +3520,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F64}.
      */
     void DTRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               double alpha, sp<Allocation> A, sp<Allocation> B);
+               double alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * CTRMM performs one of the matrix-matrix operations
@@ -3538,7 +3538,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F32_2}.
      */
     void CTRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               Float2 alpha, sp<Allocation> A, sp<Allocation> B);
+               Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * ZTRMM performs one of the matrix-matrix operations
@@ -3556,7 +3556,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F64_2}.
      */
     void ZTRMM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               Double2 alpha, sp<Allocation> A, sp<Allocation> B);
+               Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * STRSM solves one of the matrix equations
@@ -3574,7 +3574,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F32}.
      */
     void STRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               float alpha, sp<Allocation> A, sp<Allocation> B);
+               float alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * DTRSM solves one of the matrix equations
@@ -3592,7 +3592,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F64}.
      */
     void DTRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               double alpha, sp<Allocation> A, sp<Allocation> B);
+               double alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * CTRSM solves one of the matrix equations
@@ -3610,7 +3610,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F32_2}.
      */
     void CTRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               Float2 alpha, sp<Allocation> A, sp<Allocation> B);
+               Float2 alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * ZTRSM solves one of the matrix equations
@@ -3628,7 +3628,7 @@
      * @param B The input allocation contains matrix B, supported elements type: {Element#F64_2}.
      */
     void ZTRSM(RsBlasSide Side, RsBlasUplo Uplo, RsBlasTranspose TransA, RsBlasDiag Diag,
-               Double2 alpha, sp<Allocation> A, sp<Allocation> B);
+               Double2 alpha, const sp<Allocation>& A, const sp<Allocation>& B);
 
     /**
      * CHEMM performs one of the matrix-matrix operations
@@ -3644,8 +3644,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
-    void CHEMM(RsBlasSide Side, RsBlasUplo Uplo, Float2 alpha, sp<Allocation> A,
-               sp<Allocation> B, Float2 beta, sp<Allocation> C);
+    void CHEMM(RsBlasSide Side, RsBlasUplo Uplo, Float2 alpha, const sp<Allocation>& A,
+               const sp<Allocation>& B, Float2 beta, const sp<Allocation>& C);
 
     /**
      * ZHEMM performs one of the matrix-matrix operations
@@ -3661,8 +3661,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2}.
      */
-    void ZHEMM(RsBlasSide Side, RsBlasUplo Uplo, Double2 alpha, sp<Allocation> A,
-               sp<Allocation> B, Double2 beta, sp<Allocation> C);
+    void ZHEMM(RsBlasSide Side, RsBlasUplo Uplo, Double2 alpha, const sp<Allocation>& A,
+               const sp<Allocation>& B, Double2 beta, const sp<Allocation>& C);
 
     /**
      * CHERK performs one of the hermitian rank k operations
@@ -3677,8 +3677,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
-    void CHERK(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha, sp<Allocation> A,
-               float beta, sp<Allocation> C);
+    void CHERK(RsBlasUplo Uplo, RsBlasTranspose Trans, float alpha, const sp<Allocation>& A,
+               float beta, const sp<Allocation>& C);
 
     /**
      * ZHERK performs one of the hermitian rank k operations
@@ -3693,8 +3693,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2}.
      */
-    void ZHERK(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha, sp<Allocation> A,
-               double beta, sp<Allocation> C);
+    void ZHERK(RsBlasUplo Uplo, RsBlasTranspose Trans, double alpha, const sp<Allocation>& A,
+               double beta, const sp<Allocation>& C);
 
     /**
      * CHER2K performs one of the hermitian rank 2k operations
@@ -3710,8 +3710,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F32_2}.
      */
-    void CHER2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha, sp<Allocation> A,
-                sp<Allocation> B, float beta, sp<Allocation> C);
+    void CHER2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Float2 alpha, const sp<Allocation>& A,
+                const sp<Allocation>& B, float beta, const sp<Allocation>& C);
 
     /**
      * ZHER2K performs one of the hermitian rank 2k operations
@@ -3727,8 +3727,8 @@
      * @param beta The scalar beta.
      * @param C The input allocation contains matrix C, supported elements type: {Element#F64_2}.
      */
-    void ZHER2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha, sp<Allocation> A,
-                sp<Allocation> B, double beta, sp<Allocation> C);
+    void ZHER2K(RsBlasUplo Uplo, RsBlasTranspose Trans, Double2 alpha, const sp<Allocation>& A,
+                const sp<Allocation>& B, double beta, const sp<Allocation>& C);
 
     /**
      * 8-bit GEMM-like operation for neural networks: C = A * Transpose(B)
@@ -3745,7 +3745,7 @@
      * @param c_offset The offset for all values in matrix C.
      * @param c_mult The multiplier for all values in matrix C, e.g C[i,j] = (C[i,j] + c_offset) * c_mult.
      **/
-    void BNNM(sp<Allocation> A, int a_offset, sp<Allocation> B, int b_offset, sp<Allocation> C,
+    void BNNM(const sp<Allocation>& A, int a_offset, const sp<Allocation>& B, int b_offset, const sp<Allocation>& C,
               int c_offset, int c_mult);
 };
 
@@ -3762,97 +3762,97 @@
      * @param[in] e Element
      * @return new ScriptIntrinsicBlend
      */
-    static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicBlend> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * sets dst = {0, 0, 0, 0}
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachClear(sp<Allocation> in, sp<Allocation> out);
+    void forEachClear(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = src
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachSrc(sp<Allocation> in, sp<Allocation> out);
+    void forEachSrc(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = dst (NOP)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachDst(sp<Allocation> in, sp<Allocation> out);
+    void forEachDst(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = src + dst * (1.0 - src.a)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachSrcOver(sp<Allocation> in, sp<Allocation> out);
+    void forEachSrcOver(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = dst + src * (1.0 - dst.a)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachDstOver(sp<Allocation> in, sp<Allocation> out);
+    void forEachDstOver(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = src * dst.a
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachSrcIn(sp<Allocation> in, sp<Allocation> out);
+    void forEachSrcIn(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = dst * src.a
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachDstIn(sp<Allocation> in, sp<Allocation> out);
+    void forEachDstIn(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = src * (1.0 - dst.a)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachSrcOut(sp<Allocation> in, sp<Allocation> out);
+    void forEachSrcOut(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = dst * (1.0 - src.a)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachDstOut(sp<Allocation> in, sp<Allocation> out);
+    void forEachDstOut(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst.rgb = src.rgb * dst.a + (1.0 - src.a) * dst.rgb
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachSrcAtop(sp<Allocation> in, sp<Allocation> out);
+    void forEachSrcAtop(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst.rgb = dst.rgb * src.a + (1.0 - dst.a) * src.rgb
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachDstAtop(sp<Allocation> in, sp<Allocation> out);
+    void forEachDstAtop(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a}
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachXor(sp<Allocation> in, sp<Allocation> out);
+    void forEachXor(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = src * dst
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachMultiply(sp<Allocation> in, sp<Allocation> out);
+    void forEachMultiply(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = min(src + dst, 1.0)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachAdd(sp<Allocation> in, sp<Allocation> out);
+    void forEachAdd(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Sets dst = max(dst - src, 0.0)
      * @param[in] in input Allocation
      * @param[in] out output Allocation
      */
-    void forEachSubtract(sp<Allocation> in, sp<Allocation> out);
+    void forEachSubtract(const sp<Allocation>& in, const sp<Allocation>& out);
 };
 
 /**
@@ -3869,17 +3869,17 @@
      * @param[in] e Element
      * @return new ScriptIntrinsicBlur
      */
-    static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicBlur> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * Sets the input of the blur.
      * @param[in] in input Allocation
      */
-    void setInput(sp<Allocation> in);
+    void setInput(const sp<Allocation>& in);
     /**
      * Runs the intrinsic.
      * @param[in] output Allocation
      */
-    void forEach(sp<Allocation> out);
+    void forEach(const sp<Allocation>& out);
     /**
      * Sets the radius of the blur. The supported range is 0 < radius <= 25.
      * @param[in] radius radius of the blur
@@ -3903,14 +3903,14 @@
      * @param[in] rs RenderScript context
      * @return new ScriptIntrinsicColorMatrix
      */
-    static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
+    static sp<ScriptIntrinsicColorMatrix> create(const sp<RS>& rs);
     /**
      * Applies the color matrix. Supported types are U8 and F32 with
      * vector lengths between 1 and 4.
      * @param[in] in input Allocation
      * @param[out] out output Allocation
      */
-    void forEach(sp<Allocation> in, sp<Allocation> out);
+    void forEach(const sp<Allocation>& in, const sp<Allocation>& out);
     /**
      * Set the value to be added after the color matrix has been
      * applied. The default value is {0, 0, 0, 0}.
@@ -3963,17 +3963,17 @@
      * @param[in] e Element
      * @return new ScriptIntrinsicConvolve3x3
      */
-    static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicConvolve3x3> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * Sets input for intrinsic.
      * @param[in] in input Allocation
      */
-    void setInput(sp<Allocation> in);
+    void setInput(const sp<Allocation>& in);
     /**
      * Launches the intrinsic.
      * @param[in] out output Allocation
      */
-    void forEach(sp<Allocation> out);
+    void forEach(const sp<Allocation>& out);
     /**
      * Sets convolution kernel.
      * @param[in] v float[9] of values
@@ -3995,17 +3995,17 @@
      * @param[in] e Element
      * @return new ScriptIntrinsicConvolve5x5
      */
-    static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicConvolve5x5> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * Sets input for intrinsic.
      * @param[in] in input Allocation
      */
-    void setInput(sp<Allocation> in);
+    void setInput(const sp<Allocation>& in);
     /**
      * Launches the intrinsic.
      * @param[in] out output Allocation
      */
-    void forEach(sp<Allocation> out);
+    void forEach(const sp<Allocation>& out);
     /**
      * Sets convolution kernel.
      * @param[in] v float[25] of values
@@ -4032,14 +4032,14 @@
      *
      * @return ScriptIntrinsicHistogram
      */
-    static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicHistogram> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * Set the output of the histogram.  32 bit integer types are
      * supported.
      *
      * @param[in] aout The output allocation
      */
-    void setOutput(sp<Allocation> aout);
+    void setOutput(const sp<Allocation>& aout);
     /**
      * Set the coefficients used for the dot product calculation. The
      * default is {0.299f, 0.587f, 0.114f, 0.f}.
@@ -4064,7 +4064,7 @@
      *
      * @param[in] ain The input image
      */
-    void forEach(sp<Allocation> ain);
+    void forEach(const sp<Allocation>& ain);
     /**
      * Process an input buffer and place the histogram into the output
      * allocation. The dot product of the input channel and the
@@ -4075,7 +4075,7 @@
      *
      * @param ain The input image
      */
-    void forEach_dot(sp<Allocation> ain);
+    void forEach_dot(const sp<Allocation>& ain);
 };
 
 /**
@@ -4102,7 +4102,7 @@
      *
      * @return ScriptIntrinsicLUT
      */
-    static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicLUT> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * Invoke the kernel and apply the lookup to each cell of ain and
      * copy to aout.
@@ -4110,7 +4110,7 @@
      * @param[in] ain Input allocation
      * @param[in] aout Output allocation
      */
-    void forEach(sp<Allocation> ain, sp<Allocation> aout);
+    void forEach(const sp<Allocation>& ain, const sp<Allocation>& aout);
     /**
      * Sets entries in LUT for the red channel.
      * @param[in] base base of region to update
@@ -4156,7 +4156,7 @@
      * @param[in] e Element
      * @return new ScriptIntrinsic
      */
-    static sp<ScriptIntrinsicResize> create(sp<RS> rs);
+    static sp<ScriptIntrinsicResize> create(const sp<RS>& rs);
 
     /**
      * Resize copy the input allocation to the output specified. The
@@ -4165,13 +4165,13 @@
      * @param[in] ain input Allocation
      * @param[in] aout output Allocation
      */
-    void forEach_bicubic(sp<Allocation> aout);
+    void forEach_bicubic(const sp<Allocation>& aout);
 
     /**
      * Set the input of the resize.
      * @param[in] lut new lookup table
      */
-    void setInput(sp<Allocation> ain);
+    void setInput(const sp<Allocation>& ain);
 };
 
 /**
@@ -4195,13 +4195,13 @@
      *
      * @return ScriptIntrinsicYuvToRGB
      */
-    static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
+    static sp<ScriptIntrinsicYuvToRGB> create(const sp<RS>& rs, const sp<const Element>& e);
     /**
      * Set the input YUV allocation.
      *
      * @param[in] ain The input allocation.
      */
-    void setInput(sp<Allocation> in);
+    void setInput(const sp<Allocation>& in);
 
     /**
      * Convert the image to RGB.
@@ -4209,7 +4209,7 @@
      * @param[in] aout Output allocation. Must match creation element
      *                 type.
      */
-    void forEach(sp<Allocation> out);
+    void forEach(const sp<Allocation>& out);
 
 };
 
@@ -4244,7 +4244,7 @@
      * @param[in] wrapT T wrapping mode
      * @param[in] anisotropy anisotropy setting
      */
-    static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
+    static sp<Sampler> create(const sp<RS>& rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
 
     /**
      * @return minification setting for the sampler
@@ -4275,7 +4275,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
+    static sp<const Sampler> CLAMP_NEAREST(const sp<RS> &rs);
     /**
      * Retrieve a sampler with min and mag set to linear and wrap modes set to
      * clamp.
@@ -4284,7 +4284,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
+    static sp<const Sampler> CLAMP_LINEAR(const sp<RS> &rs);
     /**
      * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
      * wrap modes set to clamp.
@@ -4293,7 +4293,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
+    static sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(const sp<RS> &rs);
     /**
      * Retrieve a sampler with min and mag set to nearest and wrap modes set to
      * wrap.
@@ -4302,7 +4302,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
+    static sp<const Sampler> WRAP_NEAREST(const sp<RS> &rs);
     /**
      * Retrieve a sampler with min and mag set to linear and wrap modes set to
      * wrap.
@@ -4311,7 +4311,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
+    static sp<const Sampler> WRAP_LINEAR(const sp<RS> &rs);
     /**
      * Retrieve a sampler with mag set to linear, min linear mipmap linear, and
      * wrap modes set to wrap.
@@ -4320,7 +4320,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
+    static sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(const sp<RS> &rs);
     /**
      * Retrieve a sampler with min and mag set to nearest and wrap modes set to
      * mirrored repeat.
@@ -4329,7 +4329,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
+    static sp<const Sampler> MIRRORED_REPEAT_NEAREST(const sp<RS> &rs);
     /**
      * Retrieve a sampler with min and mag set to linear and wrap modes set to
      * mirrored repeat.
@@ -4338,7 +4338,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
+    static sp<const Sampler> MIRRORED_REPEAT_LINEAR(const sp<RS> &rs);
     /**
      * Retrieve a sampler with min and mag set to linear and wrap modes set to
      * mirrored repeat.
@@ -4347,7 +4347,7 @@
      *
      * @return Sampler
      */
-    static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
+    static sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(const sp<RS> &rs);
 
 };