From d8f45b3c9f6bc16c74e17b7269269193b0d94f18 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 13 Mar 2017 13:26:51 -0400 Subject: Replace discrete array with a map. There is one use of the discrete array, GFGAS_GEFont. This CL replaces that usage with a std::map and removes the fgas_util classes. Change-Id: Ic45812168e9487ebac08abaa131c58080a949d69 Reviewed-on: https://pdfium-review.googlesource.com/2953 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- xfa/fgas/crt/fgas_utils.cpp | 77 --------------------------------------------- xfa/fgas/crt/fgas_utils.h | 42 ------------------------- 2 files changed, 119 deletions(-) delete mode 100644 xfa/fgas/crt/fgas_utils.cpp delete mode 100644 xfa/fgas/crt/fgas_utils.h (limited to 'xfa/fgas/crt') diff --git a/xfa/fgas/crt/fgas_utils.cpp b/xfa/fgas/crt/fgas_utils.cpp deleted file mode 100644 index 5b7c72f6a4..0000000000 --- a/xfa/fgas/crt/fgas_utils.cpp +++ /dev/null @@ -1,77 +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 "xfa/fgas/crt/fgas_utils.h" - -#include - -#include "core/fxcrt/fx_basic.h" - -struct FX_BASEDISCRETEARRAYDATA { - int32_t iBlockSize; - int32_t iChunkSize; - int32_t iChunkCount; - CFX_ArrayTemplate ChunkBuffer; -}; - -CFX_BaseDiscreteArray::CFX_BaseDiscreteArray(int32_t iChunkSize, - int32_t iBlockSize) { - ASSERT(iChunkSize > 0 && iBlockSize > 0); - FX_BASEDISCRETEARRAYDATA* pData = new FX_BASEDISCRETEARRAYDATA; - m_pData = pData; - pData->ChunkBuffer.SetSize(16); - pData->iChunkCount = 0; - pData->iChunkSize = iChunkSize; - pData->iBlockSize = iBlockSize; -} -CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() { - RemoveAll(); - delete static_cast(m_pData); -} -uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) { - ASSERT(index > -1); - FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; - int32_t& iChunkCount = pData->iChunkCount; - int32_t iChunkSize = pData->iChunkSize; - uint8_t* pChunk = nullptr; - int32_t iChunk = index / iChunkSize; - if (iChunk < iChunkCount) { - pChunk = pData->ChunkBuffer.GetAt(iChunk); - } - if (!pChunk) { - pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize); - FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize); - pData->ChunkBuffer.SetAtGrow(iChunk, pChunk); - if (iChunkCount <= iChunk) { - iChunkCount = iChunk + 1; - } - } - return pChunk + (index % iChunkSize) * pData->iBlockSize; -} -uint8_t* CFX_BaseDiscreteArray::GetAt(int32_t index) const { - ASSERT(index >= 0); - FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; - int32_t iChunkSize = pData->iChunkSize; - int32_t iChunk = index / iChunkSize; - if (iChunk >= pData->iChunkCount) - return nullptr; - - uint8_t* pChunk = pData->ChunkBuffer.GetAt(iChunk); - if (!pChunk) - return nullptr; - - return pChunk + (index % iChunkSize) * pData->iBlockSize; -} -void CFX_BaseDiscreteArray::RemoveAll() { - FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; - CFX_ArrayTemplate& ChunkBuffer = pData->ChunkBuffer; - int32_t& iChunkCount = pData->iChunkCount; - for (int32_t i = 0; i < iChunkCount; i++) - FX_Free(ChunkBuffer.GetAt(i)); - - ChunkBuffer.RemoveAll(); - iChunkCount = 0; -} diff --git a/xfa/fgas/crt/fgas_utils.h b/xfa/fgas/crt/fgas_utils.h deleted file mode 100644 index 85f5e47310..0000000000 --- a/xfa/fgas/crt/fgas_utils.h +++ /dev/null @@ -1,42 +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 - -#ifndef XFA_FGAS_CRT_FGAS_UTILS_H_ -#define XFA_FGAS_CRT_FGAS_UTILS_H_ - -#include "core/fxcrt/fx_coordinates.h" - -class CFX_BaseDiscreteArray { - protected: - CFX_BaseDiscreteArray(int32_t iChunkSize, int32_t iBlockSize); - ~CFX_BaseDiscreteArray(); - - uint8_t* AddSpaceTo(int32_t index); - uint8_t* GetAt(int32_t index) const; - void RemoveAll(); - void* m_pData; -}; - -template -class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { - public: - explicit CFX_DiscreteArrayTemplate(int32_t iChunkSize) - : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} - - baseType& GetAt(int32_t index, const baseType& defValue) const { - baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); - return p ? *p : (baseType&)defValue; - } - baseType* GetPtrAt(int32_t index) const { - return (baseType*)CFX_BaseDiscreteArray::GetAt(index); - } - void SetAtGrow(int32_t index, const baseType& element) { - *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; - } - void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } -}; - -#endif // XFA_FGAS_CRT_FGAS_UTILS_H_ -- cgit v1.2.3