From 56da82820ecfff29166efd006d26935d9f3d2149 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Tue, 7 Feb 2017 17:41:16 -0800 Subject: Avoid aliasing CodedInputStream::buffer_ when parsing little endian integers. This eliminates an unnecessary reload of buffer_ that occurs (before this change) after the store to *value. --- src/google/protobuf/io/coded_stream.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/google/protobuf/io/coded_stream.h') diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 557312d3..399c6248 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -996,8 +996,7 @@ inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { #if defined(PROTOBUF_LITTLE_ENDIAN) if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { - memcpy(value, buffer_, sizeof(*value)); - Advance(sizeof(*value)); + buffer_ = ReadLittleEndian32FromArray(buffer_, value); return true; } else { return ReadLittleEndian32Fallback(value); @@ -1010,8 +1009,7 @@ inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { #if defined(PROTOBUF_LITTLE_ENDIAN) if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { - memcpy(value, buffer_, sizeof(*value)); - Advance(sizeof(*value)); + buffer_ = ReadLittleEndian64FromArray(buffer_, value); return true; } else { return ReadLittleEndian64Fallback(value); -- cgit v1.2.3