aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-10-23 18:11:42 +0200
committerShauren <shauren.trinity@gmail.com>2014-10-23 18:11:42 +0200
commit2f368984094181f2aa9b1ae1c73ce182469e5037 (patch)
tree31847ae783866c3ef0004c95ec49c0d1cc1d10ef /src
parent08c56eb1109aed2c6dabe728c945d4afd4943753 (diff)
Core/Misc: Optimized ByteBuffer::ReadString
Diffstat (limited to 'src')
-rw-r--r--src/server/shared/Packets/ByteBuffer.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 13e96833c82..069b783a537 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -498,13 +498,16 @@ class ByteBuffer
std::string ReadString(uint32 length)
{
+ if (_rpos + length > size())
+ throw ByteBufferPositionException(false, _rpos, length, size());
+
if (!length)
return std::string();
- char* buffer = new char[length + 1];
- read((uint8*)buffer, length);
- std::string retval = buffer;
- delete[] buffer;
- return retval;
+
+ ResetBitPos();
+ std::string str((char const*)&_storage[_rpos], length);
+ _rpos += length;
+ return str;
}
//! Method for writing strings that have their length sent separately in packet