From 46143e1262f2588f60370b5d3cf7e9d62505c22e Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 21 Jun 2017 11:52:35 -0700 Subject: Replace MallocHelper with std::unique_ptr. Obviously this code could be cleaned up more, but I doubt anyone wants to. Minimal change to remove MallocHelper. Bug: https://issuetracker.google.com/36982134 Test: builds, boots Change-Id: I138739c281cc2ad9723d1eea3546bf5c797ade90 --- core/jni/android/opengl/util.cpp | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index d4735ec3c94f..41d911150d93 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -49,27 +49,6 @@ void mx4transform(float x, float y, float z, float w, const float* pM, float* pD pDest[3] = pM[3 + 4 * 0] * x + pM[3 + 4 * 1] * y + pM[3 + 4 * 2] * z + pM[3 + 4 * 3] * w; } -class MallocHelper { -public: - MallocHelper() { - mData = 0; - } - - ~MallocHelper() { - if (mData != 0) { - free(mData); - } - } - - void* alloc(size_t size) { - mData = malloc(size); - return mData; - } - -private: - void* mData; -}; - #if 0 static void @@ -85,10 +64,7 @@ print_poly(const char* label, Poly* pPoly) { static int visibilityTest(float* pWS, float* pPositions, int positionsLength, unsigned short* pIndices, int indexCount) { - MallocHelper mallocHelper; int result = POLY_CLIP_OUT; - float* pTransformed = 0; - int transformedIndexCount = 0; if ( indexCount < 3 ) { return POLY_CLIP_OUT; @@ -116,8 +92,9 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength, return -1; } - transformedIndexCount = maxIndex - minIndex + 1; - pTransformed = (float*) mallocHelper.alloc(transformedIndexCount * 4 * sizeof(float)); + int transformedIndexCount = maxIndex - minIndex + 1; + std::unique_ptr holder{new float[transformedIndexCount * 4]}; + float* pTransformed = holder.get(); if (pTransformed == 0 ) { return -2; -- cgit v1.2.3-59-g8ed1b