summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/FastNBT.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-03-18 21:49:08 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-03-18 21:49:08 +0100
commitb8fe024f9de9988b8aa2fc86a1d52b8dbf5712df (patch)
tree93afcc6d60f697fe59a12b4e67a780a0c7a3907e /src/WorldStorage/FastNBT.cpp
parentAdded levels of shrapnel (diff)
parentFixed chunkmap tree block replacing. (diff)
downloadcuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.tar
cuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.tar.gz
cuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.tar.bz2
cuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.tar.lz
cuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.tar.xz
cuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.tar.zst
cuberite-b8fe024f9de9988b8aa2fc86a1d52b8dbf5712df.zip
Diffstat (limited to 'src/WorldStorage/FastNBT.cpp')
-rw-r--r--src/WorldStorage/FastNBT.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
index 8f80c3f75..be25fd1a4 100644
--- a/src/WorldStorage/FastNBT.cpp
+++ b/src/WorldStorage/FastNBT.cpp
@@ -506,22 +506,18 @@ void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, si
{
TagCommon(a_Name, TAG_IntArray);
Int32 len = htonl(a_NumElements);
+ size_t cap = m_Result.capacity();
+ size_t size = m_Result.length();
+ if ((cap - size) < (4 + a_NumElements * 4))
+ {
+ m_Result.reserve(size + 4 + (a_NumElements * 4));
+ }
m_Result.append((const char *)&len, 4);
-#if defined(ANDROID_NDK)
- // Android has alignment issues - cannot byteswap (htonl) an int that is not 32-bit-aligned, which happens in the regular version
for (size_t i = 0; i < a_NumElements; i++)
{
int Element = htonl(a_Value[i]);
m_Result.append((const char *)&Element, 4);
}
-#else
- int * Elements = (int *)(m_Result.data() + m_Result.size());
- m_Result.append(a_NumElements * 4, (char)0);
- for (size_t i = 0; i < a_NumElements; i++)
- {
- Elements[i] = htonl(a_Value[i]);
- }
-#endif
}