sources/network/bytestream.cpp

changeset 180
2e7225dbd9b2
parent 173
248fba6d1e76
child 182
20ca0a6be175
--- a/sources/network/bytestream.cpp	Wed Jan 27 13:02:51 2021 +0200
+++ b/sources/network/bytestream.cpp	Wed Jan 27 13:08:51 2021 +0200
@@ -66,7 +66,7 @@
 /*!
  * \returns an iterator to the current data position.
  */
-ByteArray::Iterator Bytestream::getCurrentIterator()
+ByteArray::iterator Bytestream::getCurrentIterator()
 {
 	return m_data.begin() + m_position;
 }
@@ -160,7 +160,7 @@
  */
 void Bytestream::writeByte(int8_t value)
 {
-	m_data.append(value);
+	m_data.push_back(value);
 }
 
 /*!
@@ -169,8 +169,9 @@
  */
 void Bytestream::writeShort(int16_t value)
 {
+	m_data.reserve(m_data.size() + 2);
 	for (int i : range(2))
-		m_data.append((value >> (i * 8)) & 0xFF);
+		m_data.push_back((value >> (i * 8)) & 0xFF);
 }
 
 /*!
@@ -179,8 +180,9 @@
  */
 void Bytestream::writeLong(int32_t value)
 {
+	m_data.reserve(m_data.size() + 4);
 	for (int i : range(4))
-		m_data.append((value >> (i * 8)) & 0xFF);
+		m_data.push_back((value >> (i * 8)) & 0xFF);
 }
 
 /*!
@@ -201,8 +203,11 @@
  */
 void Bytestream::writeString(const String& string)
 {
-	m_data.append(string.toBytes(), string.length());
-	m_data.append(0);
+	const int oldSize = m_data.size();
+	m_data.reserve(m_data.size() + string.length() + 1);
+	m_data.resize(m_data.size() + string.length());
+	std::copy(string.begin(), string.end(), m_data.begin() + oldSize);
+	m_data.push_back(0);
 }
 
 /*!

mercurial