Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h

Issue 1322483002: Revert https://codereview.chromium.org/1291903002 (protobuf roll). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h
diff --git a/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h
index 4360b18f5e918425f7d4851f752354ea54781781..153f543ee4b0cb25656f86c09b3a5bc4349aba9a 100644
--- a/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h
@@ -1,6 +1,6 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
+// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -48,7 +48,6 @@
#include <iosfwd>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/stl_util.h>
namespace google {
@@ -127,10 +126,8 @@ class LIBPROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream {
class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream {
public:
// Create a StringOutputStream which appends bytes to the given string.
- // The string remains property of the caller, but it is mutated in arbitrary
- // ways and MUST NOT be accessed in any way until you're done with the
- // stream. Either be sure there's no further usage, or (safest) destroy the
- // stream before using the contents.
+ // The string remains property of the caller, but it MUST NOT be accessed
+ // in any way until the stream is destroyed.
//
// Hint: If you call target->reserve(n) before creating the stream,
// the first call to Next() will return at least n bytes of buffer
@@ -336,44 +333,6 @@ class LIBPROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStrea
// ===================================================================
-// mutable_string_data() and as_string_data() are workarounds to improve
-// the performance of writing new data to an existing string. Unfortunately
-// the methods provided by the string class are suboptimal, and using memcpy()
-// is mildly annoying because it requires its pointer args to be non-NULL even
-// if we ask it to copy 0 bytes. Furthermore, string_as_array() has the
-// property that it always returns NULL if its arg is the empty string, exactly
-// what we want to avoid if we're using it in conjunction with memcpy()!
-// With C++11, the desired memcpy() boils down to memcpy(..., &(*s)[0], size),
-// where s is a string*. Without C++11, &(*s)[0] is not guaranteed to be safe,
-// so we use string_as_array(), and live with the extra logic that tests whether
-// *s is empty.
-
-// Return a pointer to mutable characters underlying the given string. The
-// return value is valid until the next time the string is resized. We
-// trust the caller to treat the return value as an array of length s->size().
-inline char* mutable_string_data(string* s) {
-#ifdef LANG_CXX11
- // This should be simpler & faster than string_as_array() because the latter
- // is guaranteed to return NULL when *s is empty, so it has to check for that.
- return &(*s)[0];
-#else
- return string_as_array(s);
-#endif
-}
-
-// as_string_data(s) is equivalent to
-// ({ char* p = mutable_string_data(s); make_pair(p, p != NULL); })
-// Sometimes it's faster: in some scenarios p cannot be NULL, and then the
-// code can avoid that check.
-inline std::pair<char*, bool> as_string_data(string* s) {
- char *p = mutable_string_data(s);
-#ifdef LANG_CXX11
- return std::make_pair(p, true);
-#else
- return make_pair(p, p != NULL);
-#endif
-}
-
} // namespace io
} // namespace protobuf

Powered by Google App Engine
This is Rietveld 408576698