summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/FastNBT.cpp
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-03-10 19:24:12 +0100
committerTycho <work.tycho+git@gmail.com>2014-03-10 19:24:12 +0100
commit8947f802940213d371863710e1c3ac873b2dc4b9 (patch)
treef311ed8e024be487927b041ec7c70294b9426fd7 /src/WorldStorage/FastNBT.cpp
parentRemoved unused macro from WSSCompact (diff)
downloadcuberite-8947f802940213d371863710e1c3ac873b2dc4b9.tar
cuberite-8947f802940213d371863710e1c3ac873b2dc4b9.tar.gz
cuberite-8947f802940213d371863710e1c3ac873b2dc4b9.tar.bz2
cuberite-8947f802940213d371863710e1c3ac873b2dc4b9.tar.lz
cuberite-8947f802940213d371863710e1c3ac873b2dc4b9.tar.xz
cuberite-8947f802940213d371863710e1c3ac873b2dc4b9.tar.zst
cuberite-8947f802940213d371863710e1c3ac873b2dc4b9.zip
Diffstat (limited to '')
-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..f1f092e0b 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
}