summaryrefslogtreecommitdiffstats
path: root/source/FastNBT.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-05-08 13:31:54 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-05-08 13:31:54 +0200
commitf2681777fb21c134cd96ae1e06bf5266a59bfd5d (patch)
treed4f9e3b5463925581a2ce6febabb44411bf3d3a4 /source/FastNBT.h
parentFixed two "bottlenecks" found using profiling - MakeIndex() instead of MakeIndexNoCheck() (diff)
downloadcuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.tar
cuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.tar.gz
cuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.tar.bz2
cuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.tar.lz
cuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.tar.xz
cuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.tar.zst
cuberite-f2681777fb21c134cd96ae1e06bf5266a59bfd5d.zip
Diffstat (limited to '')
-rw-r--r--source/FastNBT.h58
1 files changed, 49 insertions, 9 deletions
diff --git a/source/FastNBT.h b/source/FastNBT.h
index fd60fc671..a0fe7a863 100644
--- a/source/FastNBT.h
+++ b/source/FastNBT.h
@@ -214,19 +214,59 @@ public:
void EndList(void);
void AddByte (const AString & a_Name, unsigned char a_Value);
- void AddShort (const AString & a_Name, unsigned char a_Value);
- void AddInt (const AString & a_Name, unsigned char a_Value);
- void AddLong (const AString & a_Name, unsigned char a_Value);
- void AddFloat (const AString & a_Name, unsigned char a_Value);
- void AddDouble (const AString & a_Name, unsigned char a_Value);
- void AddString (const AString & a_Name, unsigned char a_Value);
- void AddByteArray(const AString & a_Name, unsigned char a_Value);
- void AddIntArray (const AString & a_Name, unsigned char a_Value);
-
+ void AddShort (const AString & a_Name, Int16 a_Value);
+ void AddInt (const AString & a_Name, Int32 a_Value);
+ void AddLong (const AString & a_Name, Int64 a_Value);
+ void AddFloat (const AString & a_Name, float a_Value);
+ void AddDouble (const AString & a_Name, double a_Value);
+ void AddString (const AString & a_Name, const AString & a_Value);
+ void AddByteArray(const AString & a_Name, const char * a_Value, size_t a_NumElements);
+ void AddIntArray (const AString & a_Name, const int * a_Value, size_t a_NumElements);
+
+ void AddByteArray(const AString & a_Name, const AString & a_Value)
+ {
+ AddByteArray(a_Name, a_Value.data(), a_Value.size());
+ }
+
const AString & GetResult(void) const {return m_Result; }
+ void Finish(void);
+
protected:
+
+ struct sParent
+ {
+ int m_Type; // TAG_Compound or TAG_List
+ int m_Pos; // for TAG_List, the position of the list count
+ int m_Count; // for TAG_List, the element count
+ } ;
+
+ static const int MAX_STACK = 50; // Highliy doubtful that an NBT would be constructed this many levels deep
+
+ // These two fields emulate a stack. A raw array is used due to speed issues - no reallocations are allowed.
+ sParent m_Stack[MAX_STACK];
+ int m_CurrentStack;
+
AString m_Result;
+
+ bool IsStackTopCompound(void) const { return (m_Stack[m_CurrentStack].m_Type == TAG_Compound); }
+
+ void WriteString(const char * a_Data, short a_Length);
+
+ inline void TagCommon(const AString & a_Name, eTagType a_Type)
+ {
+ if (IsStackTopCompound())
+ {
+ // Compound: add the type and name:
+ m_Result.push_back((char)a_Type);
+ WriteString(a_Name.c_str(), a_Name.length());
+ }
+ else
+ {
+ // List: add to the counter
+ m_Stack[m_CurrentStack].m_Count++;
+ }
+ }
} ;