From 022ded02d2c23a8d043bbcb3d3f37dab12636759 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 28 Mar 2017 11:33:37 -0700 Subject: Remove unused CFX_ArrayTemplate and CFX_BasicArray. Change-Id: I10040b6504cf237f2e3e1f6075ae6a0612570461 Reviewed-on: https://pdfium-review.googlesource.com/3249 Reviewed-by: dsinclair Commit-Queue: dsinclair --- BUILD.gn | 1 - core/fxcrt/fx_basic.h | 141 ------------------------------------------ core/fxcrt/fx_basic_array.cpp | 138 ----------------------------------------- 3 files changed, 280 deletions(-) delete mode 100644 core/fxcrt/fx_basic_array.cpp diff --git a/BUILD.gn b/BUILD.gn index 58798d9907..d327c6093f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -758,7 +758,6 @@ static_library("fxcrt") { "core/fxcrt/cfx_weak_ptr.h", "core/fxcrt/extension.h", "core/fxcrt/fx_basic.h", - "core/fxcrt/fx_basic_array.cpp", "core/fxcrt/fx_basic_bstring.cpp", "core/fxcrt/fx_basic_buffer.cpp", "core/fxcrt/fx_basic_coords.cpp", diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index 076766a0a2..77df71e125 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -176,147 +176,6 @@ class CFX_UTF8Encoder { CFX_ByteTextBuf m_Buffer; }; -class CFX_BasicArray { - protected: - explicit CFX_BasicArray(int unit_size); - CFX_BasicArray(const CFX_BasicArray&) = delete; - ~CFX_BasicArray(); - - bool SetSize(int nNewSize); - bool Append(const CFX_BasicArray& src); - bool Copy(const CFX_BasicArray& src); - uint8_t* InsertSpaceAt(int nIndex, int nCount); - bool RemoveAt(int nIndex, int nCount); - bool InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray); - const void* GetDataPtr(int index) const; - - protected: - uint8_t* m_pData; - int m_nSize; - int m_nMaxSize; - int m_nUnitSize; -}; - -template -class CFX_ArrayTemplate : public CFX_BasicArray { - public: - CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} - - int GetSize() const { return m_nSize; } - - int GetUpperBound() const { return m_nSize - 1; } - - bool SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } - - void RemoveAll() { SetSize(0); } - - const TYPE GetAt(int nIndex) const { - if (nIndex < 0 || nIndex >= m_nSize) { - PDFIUM_IMMEDIATE_CRASH(); - } - return ((const TYPE*)m_pData)[nIndex]; - } - - bool SetAt(int nIndex, TYPE newElement) { - if (nIndex < 0 || nIndex >= m_nSize) { - return false; - } - ((TYPE*)m_pData)[nIndex] = newElement; - return true; - } - - TYPE& ElementAt(int nIndex) { - if (nIndex < 0 || nIndex >= m_nSize) { - PDFIUM_IMMEDIATE_CRASH(); - } - return ((TYPE*)m_pData)[nIndex]; - } - - const TYPE* GetData() const { return (const TYPE*)m_pData; } - - TYPE* GetData() { return (TYPE*)m_pData; } - - bool SetAtGrow(int nIndex, TYPE newElement) { - if (nIndex < 0) - return false; - - if (nIndex >= m_nSize && !SetSize(nIndex + 1)) - return false; - - ((TYPE*)m_pData)[nIndex] = newElement; - return true; - } - - bool Add(TYPE newElement) { - if (m_nSize < m_nMaxSize) { - m_nSize++; - } else if (!SetSize(m_nSize + 1)) { - return false; - } - ((TYPE*)m_pData)[m_nSize - 1] = newElement; - return true; - } - - bool Append(const CFX_ArrayTemplate& src) { - return CFX_BasicArray::Append(src); - } - - bool Copy(const CFX_ArrayTemplate& src) { return CFX_BasicArray::Copy(src); } - - TYPE* GetDataPtr(int index) { - return (TYPE*)CFX_BasicArray::GetDataPtr(index); - } - - TYPE* AddSpace() { return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); } - - TYPE* InsertSpaceAt(int nIndex, int nCount) { - return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount); - } - - const TYPE operator[](int nIndex) const { - if (nIndex < 0 || nIndex >= m_nSize) { - *(volatile char*)0 = '\0'; - } - return ((const TYPE*)m_pData)[nIndex]; - } - - TYPE& operator[](int nIndex) { - if (nIndex < 0 || nIndex >= m_nSize) { - *(volatile char*)0 = '\0'; - } - return ((TYPE*)m_pData)[nIndex]; - } - - bool InsertAt(int nIndex, TYPE newElement, int nCount = 1) { - if (!InsertSpaceAt(nIndex, nCount)) { - return false; - } - while (nCount--) { - ((TYPE*)m_pData)[nIndex++] = newElement; - } - return true; - } - - bool RemoveAt(int nIndex, int nCount = 1) { - return CFX_BasicArray::RemoveAt(nIndex, nCount); - } - - bool InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) { - return CFX_BasicArray::InsertAt(nStartIndex, pNewArray); - } - - int Find(TYPE data, int iStart = 0) const { - if (iStart < 0) { - return -1; - } - for (; iStart < (int)m_nSize; iStart++) - if (((TYPE*)m_pData)[iStart] == data) { - return iStart; - } - return -1; - } -}; - template class CFX_FixedBufGrow { public: diff --git a/core/fxcrt/fx_basic_array.cpp b/core/fxcrt/fx_basic_array.cpp deleted file mode 100644 index 83c981e9e7..0000000000 --- a/core/fxcrt/fx_basic_array.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcrt/fx_basic.h" -#include "third_party/base/numerics/safe_math.h" - -CFX_BasicArray::CFX_BasicArray(int unit_size) - : m_pData(nullptr), m_nSize(0), m_nMaxSize(0) { - if (unit_size < 0 || unit_size > (1 << 28)) { - m_nUnitSize = 4; - } else { - m_nUnitSize = unit_size; - } -} -CFX_BasicArray::~CFX_BasicArray() { - FX_Free(m_pData); -} -bool CFX_BasicArray::SetSize(int nNewSize) { - if (nNewSize <= 0) { - FX_Free(m_pData); - m_pData = nullptr; - m_nSize = m_nMaxSize = 0; - return 0 == nNewSize; - } - - if (!m_pData) { - pdfium::base::CheckedNumeric totalSize = nNewSize; - totalSize *= m_nUnitSize; - if (!totalSize.IsValid()) { - m_nSize = m_nMaxSize = 0; - return false; - } - m_pData = - FX_Alloc(uint8_t, pdfium::base::ValueOrDieForType(totalSize)); - m_nSize = m_nMaxSize = nNewSize; - } else if (nNewSize <= m_nMaxSize) { - if (nNewSize > m_nSize) { - FXSYS_memset(m_pData + m_nSize * m_nUnitSize, 0, - (nNewSize - m_nSize) * m_nUnitSize); - } - m_nSize = nNewSize; - } else { - int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; - pdfium::base::CheckedNumeric totalSize = nNewMax; - totalSize *= m_nUnitSize; - if (!totalSize.IsValid() || nNewMax < m_nSize) { - return false; - } - uint8_t* pNewData = FX_Realloc( - uint8_t, m_pData, pdfium::base::ValueOrDieForType(totalSize)); - if (!pNewData) { - return false; - } - FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0, - (nNewMax - m_nSize) * m_nUnitSize); - m_pData = pNewData; - m_nSize = nNewSize; - m_nMaxSize = nNewMax; - } - return true; -} -bool CFX_BasicArray::Append(const CFX_BasicArray& src) { - int nOldSize = m_nSize; - pdfium::base::CheckedNumeric newSize = m_nSize; - newSize += src.m_nSize; - if (m_nUnitSize != src.m_nUnitSize || !newSize.IsValid() || - !SetSize(newSize.ValueOrDie())) { - return false; - } - - FXSYS_memcpy(m_pData + nOldSize * m_nUnitSize, src.m_pData, - src.m_nSize * m_nUnitSize); - return true; -} -bool CFX_BasicArray::Copy(const CFX_BasicArray& src) { - if (!SetSize(src.m_nSize)) { - return false; - } - FXSYS_memcpy(m_pData, src.m_pData, src.m_nSize * m_nUnitSize); - return true; -} -uint8_t* CFX_BasicArray::InsertSpaceAt(int nIndex, int nCount) { - if (nIndex < 0 || nCount <= 0) { - return nullptr; - } - if (nIndex >= m_nSize) { - if (!SetSize(nIndex + nCount)) { - return nullptr; - } - } else { - int nOldSize = m_nSize; - if (!SetSize(m_nSize + nCount)) { - return nullptr; - } - FXSYS_memmove(m_pData + (nIndex + nCount) * m_nUnitSize, - m_pData + nIndex * m_nUnitSize, - (nOldSize - nIndex) * m_nUnitSize); - FXSYS_memset(m_pData + nIndex * m_nUnitSize, 0, nCount * m_nUnitSize); - } - return m_pData + nIndex * m_nUnitSize; -} -bool CFX_BasicArray::RemoveAt(int nIndex, int nCount) { - if (nIndex < 0 || nCount <= 0 || m_nSize < nIndex + nCount) { - return false; - } - int nMoveCount = m_nSize - (nIndex + nCount); - if (nMoveCount) { - FXSYS_memmove(m_pData + nIndex * m_nUnitSize, - m_pData + (nIndex + nCount) * m_nUnitSize, - nMoveCount * m_nUnitSize); - } - m_nSize -= nCount; - return true; -} -bool CFX_BasicArray::InsertAt(int nStartIndex, - const CFX_BasicArray* pNewArray) { - if (!pNewArray) { - return false; - } - if (pNewArray->m_nSize == 0) { - return true; - } - if (!InsertSpaceAt(nStartIndex, pNewArray->m_nSize)) { - return false; - } - FXSYS_memcpy(m_pData + nStartIndex * m_nUnitSize, pNewArray->m_pData, - pNewArray->m_nSize * m_nUnitSize); - return true; -} -const void* CFX_BasicArray::GetDataPtr(int index) const { - if (index < 0 || index >= m_nSize || !m_pData) { - return nullptr; - } - return m_pData + index * m_nUnitSize; -} -- cgit v1.2.3