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

Unified Diff: third_party/WebKit/Source/core/fetch/CachedMetadata.cpp

Issue 2258743002: Reserve Vector's capacity manually in CachedMetadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 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/WebKit/Source/core/fetch/CachedMetadata.cpp
diff --git a/third_party/WebKit/Source/core/fetch/CachedMetadata.cpp b/third_party/WebKit/Source/core/fetch/CachedMetadata.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6df3804f4225432bf885018a9db8d3993386a3f6
--- /dev/null
+++ b/third_party/WebKit/Source/core/fetch/CachedMetadata.cpp
@@ -0,0 +1,32 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fetch/CachedMetadata.h"
+
+namespace blink {
+
+CachedMetadata::CachedMetadata(const char* data, size_t size)
+{
+ // We need to define a local variable to use the constant in DCHECK.
+ constexpr auto kDataStart = CachedMetadata::kDataStart;
+ // Serialized metadata should have non-empty data.
+ DCHECK_GT(size, kDataStart);
+ DCHECK(data);
+
+ m_serializedData.reserveInitialCapacity(size);
+ m_serializedData.append(data, size);
+}
+
+CachedMetadata::CachedMetadata(uint32_t dataTypeID, const char* data, size_t size)
+{
+ // Don't allow an ID of 0, it is used internally to indicate errors.
+ DCHECK(dataTypeID);
+ DCHECK(data);
+
+ m_serializedData.reserveInitialCapacity(sizeof(uint32_t) + size);
+ m_serializedData.append(reinterpret_cast<const char*>(&dataTypeID), sizeof(uint32_t));
+ m_serializedData.append(data, size);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CachedMetadata.h ('k') | third_party/WebKit/Source/core/fetch/CachedMetadataHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698