aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/io
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2016-09-19 13:45:07 -0700
committerGravatar Bo Yang <teboring@google.com>2016-10-10 11:23:36 -0700
commitcc8ca5b6a5478b40546d4206392eb1471454460d (patch)
treec0b45abfa16d7d373a6ea8f7fe50f1de00ab938e /src/google/protobuf/io
parent337a028bb65ccca4dda768695950b5aba53ae2c9 (diff)
Integrate internal changes
Diffstat (limited to 'src/google/protobuf/io')
-rw-r--r--src/google/protobuf/io/coded_stream.cc45
-rw-r--r--src/google/protobuf/io/coded_stream.h14
-rw-r--r--src/google/protobuf/io/coded_stream_unittest.cc1
-rw-r--r--src/google/protobuf/io/zero_copy_stream_impl.h12
4 files changed, 23 insertions, 49 deletions
diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc
index a5675e79..08394ca7 100644
--- a/src/google/protobuf/io/coded_stream.cc
+++ b/src/google/protobuf/io/coded_stream.cc
@@ -47,6 +47,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stl_util.h>
+#include <google/protobuf/stubs/port.h>
namespace google {
@@ -902,46 +903,18 @@ bool CodedOutputStream::Refresh() {
}
}
-int CodedOutputStream::VarintSize32Fallback(uint32 value) {
+size_t CodedOutputStream::VarintSize32Fallback(uint32 value) {
+ GOOGLE_DCHECK_NE(0, value); // This is enforced by our caller.
+
+ return 1 + Bits::Log2FloorNonZero(value) / 7;
+}
+
+size_t CodedOutputStream::VarintSize64(uint64 value) {
if (value < (1 << 7)) {
return 1;
- } else if (value < (1 << 14)) {
- return 2;
- } else if (value < (1 << 21)) {
- return 3;
- } else if (value < (1 << 28)) {
- return 4;
- } else {
- return 5;
}
-}
-int CodedOutputStream::VarintSize64(uint64 value) {
- if (value < (1ull << 35)) {
- if (value < (1ull << 7)) {
- return 1;
- } else if (value < (1ull << 14)) {
- return 2;
- } else if (value < (1ull << 21)) {
- return 3;
- } else if (value < (1ull << 28)) {
- return 4;
- } else {
- return 5;
- }
- } else {
- if (value < (1ull << 42)) {
- return 6;
- } else if (value < (1ull << 49)) {
- return 7;
- } else if (value < (1ull << 56)) {
- return 8;
- } else if (value < (1ull << 63)) {
- return 9;
- } else {
- return 10;
- }
- }
+ return 1 + Bits::Log2FloorNonZero64(value) / 7;
}
uint8* CodedOutputStream::WriteStringWithSizeToArray(const string& str,
diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h
index 316da765..1402cc17 100644
--- a/src/google/protobuf/io/coded_stream.h
+++ b/src/google/protobuf/io/coded_stream.h
@@ -784,17 +784,17 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
uint8* target);
// Returns the number of bytes needed to encode the given value as a varint.
- static int VarintSize32(uint32 value);
+ static size_t VarintSize32(uint32 value);
// Returns the number of bytes needed to encode the given value as a varint.
- static int VarintSize64(uint64 value);
+ static size_t VarintSize64(uint64 value);
// If negative, 10 bytes. Otheriwse, same as VarintSize32().
- static int VarintSize32SignExtended(int32 value);
+ static size_t VarintSize32SignExtended(int32 value);
// Compile-time equivalent of VarintSize32().
template <uint32 Value>
struct StaticVarintSize32 {
- static const int value =
+ static const size_t value =
(Value < (1 << 7))
? 1
: (Value < (1 << 14))
@@ -890,7 +890,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteVarint64ToArrayInline(
uint64 value, uint8* target);
- static int VarintSize32Fallback(uint32 value);
+ static size_t VarintSize32Fallback(uint32 value);
// See above. Other projects may use "friend" to allow them to call this.
static void SetDefaultSerializationDeterministic() {
@@ -1225,7 +1225,7 @@ inline uint8* CodedOutputStream::WriteTagToArray(
return WriteVarint32ToArray(value, target);
}
-inline int CodedOutputStream::VarintSize32(uint32 value) {
+inline size_t CodedOutputStream::VarintSize32(uint32 value) {
if (value < (1 << 7)) {
return 1;
} else {
@@ -1233,7 +1233,7 @@ inline int CodedOutputStream::VarintSize32(uint32 value) {
}
}
-inline int CodedOutputStream::VarintSize32SignExtended(int32 value) {
+inline size_t CodedOutputStream::VarintSize32SignExtended(int32 value) {
if (value < 0) {
return 10; // TODO(kenton): Make this a symbolic constant.
} else {
diff --git a/src/google/protobuf/io/coded_stream_unittest.cc b/src/google/protobuf/io/coded_stream_unittest.cc
index a8108e45..9f1ebc3f 100644
--- a/src/google/protobuf/io/coded_stream_unittest.cc
+++ b/src/google/protobuf/io/coded_stream_unittest.cc
@@ -58,6 +58,7 @@
#define ULL(x) GOOGLE_ULONGLONG(x)
namespace google {
+
namespace protobuf {
namespace io {
namespace {
diff --git a/src/google/protobuf/io/zero_copy_stream_impl.h b/src/google/protobuf/io/zero_copy_stream_impl.h
index 0746fa6a..3365790e 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl.h
+++ b/src/google/protobuf/io/zero_copy_stream_impl.h
@@ -218,7 +218,7 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream {
// If a block_size is given, it specifies the number of bytes that
// should be read and returned with each call to Next(). Otherwise,
// a reasonable default is used.
- explicit IstreamInputStream(istream* stream, int block_size = -1);
+ explicit IstreamInputStream(std::istream* stream, int block_size = -1);
~IstreamInputStream();
// implements ZeroCopyInputStream ----------------------------------
@@ -230,7 +230,7 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream {
private:
class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream {
public:
- CopyingIstreamInputStream(istream* input);
+ CopyingIstreamInputStream(std::istream* input);
~CopyingIstreamInputStream();
// implements CopyingInputStream ---------------------------------
@@ -239,7 +239,7 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream {
private:
// The stream.
- istream* input_;
+ std::istream* input_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream);
};
@@ -262,7 +262,7 @@ class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream {
// If a block_size is given, it specifies the size of the buffers
// that should be returned by Next(). Otherwise, a reasonable default
// is used.
- explicit OstreamOutputStream(ostream* stream, int block_size = -1);
+ explicit OstreamOutputStream(std::ostream* stream, int block_size = -1);
~OstreamOutputStream();
// implements ZeroCopyOutputStream ---------------------------------
@@ -273,7 +273,7 @@ class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream {
private:
class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStream {
public:
- CopyingOstreamOutputStream(ostream* output);
+ CopyingOstreamOutputStream(std::ostream* output);
~CopyingOstreamOutputStream();
// implements CopyingOutputStream --------------------------------
@@ -281,7 +281,7 @@ class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream {
private:
// The stream.
- ostream* output_;
+ std::ostream* output_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream);
};