summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xfa/src/fgas/include/fx_mem.h3
-rw-r--r--xfa/src/fgas/include/fx_utl.h10
-rw-r--r--xfa/src/fgas/src/crt/fx_utils.cpp82
3 files changed, 50 insertions, 45 deletions
diff --git a/xfa/src/fgas/include/fx_mem.h b/xfa/src/fgas/include/fx_mem.h
index fe52489c6b..313fc935cc 100644
--- a/xfa/src/fgas/include/fx_mem.h
+++ b/xfa/src/fgas/include/fx_mem.h
@@ -6,6 +6,9 @@
#ifndef _FX_MEMORY
#define _FX_MEMORY
+
+#include "../../../../core/include/fxcrt/fx_memory.h" // For FX_Alloc().
+
class IFX_MEMAllocator;
class CFX_Target;
enum FX_ALLOCTYPE {
diff --git a/xfa/src/fgas/include/fx_utl.h b/xfa/src/fgas/include/fx_utl.h
index 86a516b530..e4fcf78aba 100644
--- a/xfa/src/fgas/include/fx_utl.h
+++ b/xfa/src/fgas/include/fx_utl.h
@@ -6,6 +6,10 @@
#ifndef _FX_UTILS
#define _FX_UTILS
+
+#include "fx_mem.h"
+#include "../../../../core/include/fxcrt/fx_coordinates.h" // For CFX_Rect.
+
class CFX_ThreadLock;
class CFX_BaseArray;
template <class baseType>
@@ -30,6 +34,8 @@ template <class baseType>
class CFX_CPLTreeNode;
template <class baseType>
class CFX_CPLTree;
+class FX_BASEARRAYDATA;
+
class CFX_ThreadLock {
public:
CFX_ThreadLock();
@@ -43,7 +49,6 @@ class CFX_ThreadLock {
class CFX_BaseArray : public CFX_Target {
protected:
CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize);
- ~CFX_BaseArray();
int32_t GetSize() const;
int32_t GetBlockSize() const;
uint8_t* AddSpaceTo(int32_t index);
@@ -57,7 +62,8 @@ class CFX_BaseArray : public CFX_Target {
int32_t iCount = -1);
int32_t RemoveLast(int32_t iCount = -1);
void RemoveAll(FX_BOOL bLeaveMemory = FALSE);
- void* m_pData;
+
+ FX_BASEARRAYDATA* m_pData;
};
template <class baseType>
class CFX_BaseArrayTemplate : public CFX_BaseArray {
diff --git a/xfa/src/fgas/src/crt/fx_utils.cpp b/xfa/src/fgas/src/crt/fx_utils.cpp
index 1b5cb6d587..95f9e5c8da 100644
--- a/xfa/src/fgas/src/crt/fx_utils.cpp
+++ b/xfa/src/fgas/src/crt/fx_utils.cpp
@@ -4,77 +4,76 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "../../include/fx_utl.h"
#include "../fgas_base.h"
#include "fx_utils.h"
+
CFX_ThreadLock::CFX_ThreadLock() : m_pData(NULL) {}
CFX_ThreadLock::~CFX_ThreadLock() {}
void CFX_ThreadLock::Lock() {}
void CFX_ThreadLock::Unlock() {}
-typedef struct _FX_BASEARRAYDATA : public CFX_Target {
+class FX_BASEARRAYDATA : public CFX_Target {
+ public:
+ FX_BASEARRAYDATA(int32_t growsize, int32_t blocksize)
+ : iGrowSize(growsize),
+ iBlockSize(blocksize),
+ iTotalCount(0),
+ iBlockCount(0),
+ pBuffer(nullptr) {}
+
+ ~FX_BASEARRAYDATA() { FX_Free(pBuffer); }
+
int32_t iGrowSize;
int32_t iBlockSize;
int32_t iTotalCount;
int32_t iBlockCount;
uint8_t* pBuffer;
-} FX_BASEARRAYDATA, *FX_LPBASEARRAYDATA;
-typedef FX_BASEARRAYDATA const* FX_LPCBASEARRAYDATA;
+};
CFX_BaseArray::CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize) {
FXSYS_assert(iGrowSize > 0 && iBlockSize > 0);
- m_pData = new FX_BASEARRAYDATA;
- FX_memset(m_pData, 0, sizeof(FX_BASEARRAYDATA));
- ((FX_LPBASEARRAYDATA)m_pData)->iGrowSize = iGrowSize;
- ((FX_LPBASEARRAYDATA)m_pData)->iBlockSize = iBlockSize;
-}
-CFX_BaseArray::~CFX_BaseArray() {
- FX_LPBASEARRAYDATA pData = (FX_LPBASEARRAYDATA)m_pData;
- if (pData->pBuffer != NULL) {
- FX_Free(pData->pBuffer);
- }
- delete pData;
+ m_pData = new FX_BASEARRAYDATA(iGrowSize, iBlockSize);
}
int32_t CFX_BaseArray::GetSize() const {
- return ((FX_LPBASEARRAYDATA)m_pData)->iBlockCount;
+ return m_pData->iBlockCount;
}
int32_t CFX_BaseArray::GetBlockSize() const {
- return ((FX_LPBASEARRAYDATA)m_pData)->iBlockSize;
+ return m_pData->iBlockSize;
}
uint8_t* CFX_BaseArray::AddSpaceTo(int32_t index) {
FXSYS_assert(index > -1);
- uint8_t*& pBuffer = ((FX_LPBASEARRAYDATA)m_pData)->pBuffer;
- int32_t& iTotalCount = ((FX_LPBASEARRAYDATA)m_pData)->iTotalCount;
- int32_t iBlockSize = ((FX_LPBASEARRAYDATA)m_pData)->iBlockSize;
+ uint8_t*& pBuffer = m_pData->pBuffer;
+ int32_t& iTotalCount = m_pData->iTotalCount;
+ int32_t iBlockSize = m_pData->iBlockSize;
if (index >= iTotalCount) {
- int32_t iGrowSize = ((FX_LPBASEARRAYDATA)m_pData)->iGrowSize;
+ int32_t iGrowSize = m_pData->iGrowSize;
iTotalCount = (index / iGrowSize + 1) * iGrowSize;
int32_t iNewSize = iTotalCount * iBlockSize;
if (pBuffer == NULL) {
- pBuffer = (uint8_t*)FX_Alloc(uint8_t, iNewSize);
+ pBuffer = FX_Alloc(uint8_t, iNewSize);
} else {
- pBuffer = (uint8_t*)FX_Realloc(uint8_t, pBuffer, iNewSize);
+ pBuffer = FX_Realloc(uint8_t, pBuffer, iNewSize);
}
}
FXSYS_assert(pBuffer != NULL);
- int32_t& iBlockCount = ((FX_LPBASEARRAYDATA)m_pData)->iBlockCount;
+ int32_t& iBlockCount = m_pData->iBlockCount;
if (index >= iBlockCount) {
iBlockCount = index + 1;
}
return pBuffer + index * iBlockSize;
}
uint8_t* CFX_BaseArray::GetAt(int32_t index) const {
- FXSYS_assert(index > -1 &&
- index < ((FX_LPBASEARRAYDATA)m_pData)->iBlockCount);
- return ((FX_LPBASEARRAYDATA)m_pData)->pBuffer +
- index * ((FX_LPBASEARRAYDATA)m_pData)->iBlockSize;
+ FXSYS_assert(index > -1 && index < m_pData->iBlockCount);
+ return m_pData->pBuffer + index * m_pData->iBlockSize;
}
uint8_t* CFX_BaseArray::GetBuffer() const {
- return ((FX_LPBASEARRAYDATA)m_pData)->pBuffer;
+ return m_pData->pBuffer;
}
int32_t CFX_BaseArray::Append(const CFX_BaseArray& src,
int32_t iStart,
int32_t iCount) {
- int32_t iBlockSize = ((FX_LPBASEARRAYDATA)m_pData)->iBlockSize;
- FXSYS_assert(iBlockSize == ((FX_LPBASEARRAYDATA)src.m_pData)->iBlockSize);
- int32_t& iBlockCount = ((FX_LPBASEARRAYDATA)m_pData)->iBlockCount;
+ int32_t iBlockSize = m_pData->iBlockSize;
+ FXSYS_assert(iBlockSize == src.m_pData->iBlockSize);
+ int32_t& iBlockCount = m_pData->iBlockCount;
int32_t iAdded = src.GetSize();
FXSYS_assert(iStart > -1 && iStart < iAdded);
if (iCount < 0) {
@@ -86,19 +85,17 @@ int32_t CFX_BaseArray::Append(const CFX_BaseArray& src,
if (iCount < 1) {
return 0;
}
- uint8_t* pDst =
- ((FX_LPBASEARRAYDATA)m_pData)->pBuffer + iBlockCount * iBlockSize;
+ uint8_t* pDst = m_pData->pBuffer + iBlockCount * iBlockSize;
AddSpaceTo(iBlockCount + iCount - 1);
- FX_memcpy(pDst,
- ((FX_LPBASEARRAYDATA)src.m_pData)->pBuffer + iStart * iBlockSize,
+ FX_memcpy(pDst, src.m_pData->pBuffer + iStart * iBlockSize,
iCount * iBlockSize);
return iCount;
}
int32_t CFX_BaseArray::Copy(const CFX_BaseArray& src,
int32_t iStart,
int32_t iCount) {
- int32_t iBlockSize = ((FX_LPBASEARRAYDATA)m_pData)->iBlockSize;
- FXSYS_assert(iBlockSize == ((FX_LPBASEARRAYDATA)src.m_pData)->iBlockSize);
+ int32_t iBlockSize = m_pData->iBlockSize;
+ FXSYS_assert(iBlockSize == src.m_pData->iBlockSize);
int32_t iCopied = src.GetSize();
FXSYS_assert(iStart > -1 && iStart < iCopied);
if (iCount < 0) {
@@ -112,13 +109,12 @@ int32_t CFX_BaseArray::Copy(const CFX_BaseArray& src,
}
RemoveAll(TRUE);
AddSpaceTo(iCount - 1);
- FX_memcpy(((FX_LPBASEARRAYDATA)m_pData)->pBuffer,
- ((FX_LPBASEARRAYDATA)src.m_pData)->pBuffer + iStart * iBlockSize,
+ FX_memcpy(m_pData->pBuffer, src.m_pData->pBuffer + iStart * iBlockSize,
iCount * iBlockSize);
return iCount;
}
int32_t CFX_BaseArray::RemoveLast(int32_t iCount) {
- int32_t& iBlockCount = ((FX_LPBASEARRAYDATA)m_pData)->iBlockCount;
+ int32_t& iBlockCount = m_pData->iBlockCount;
if (iCount < 0 || iCount > iBlockCount) {
iCount = iBlockCount;
iBlockCount = 0;
@@ -129,14 +125,14 @@ int32_t CFX_BaseArray::RemoveLast(int32_t iCount) {
}
void CFX_BaseArray::RemoveAll(FX_BOOL bLeaveMemory) {
if (!bLeaveMemory) {
- uint8_t*& pBuffer = ((FX_LPBASEARRAYDATA)m_pData)->pBuffer;
+ uint8_t*& pBuffer = m_pData->pBuffer;
if (pBuffer != NULL) {
FX_Free(pBuffer);
pBuffer = NULL;
}
- ((FX_LPBASEARRAYDATA)m_pData)->iTotalCount = 0;
+ m_pData->iTotalCount = 0;
}
- ((FX_LPBASEARRAYDATA)m_pData)->iBlockCount = 0;
+ m_pData->iBlockCount = 0;
}
CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize,
int32_t iBlockSize)