summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-19 13:08:31 +0000
committerpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-19 13:08:31 +0000
commit31c406b1b4fe7b0060fab563040bd3cd0d4ccf1e (patch)
treefb414d38797177cf186bb9f1031036c00c68997b
parent67e596f60f44aed4818b845c623de7b3bde0d759 (diff)
downloadchromium_src-31c406b1b4fe7b0060fab563040bd3cd0d4ccf1e.zip
chromium_src-31c406b1b4fe7b0060fab563040bd3cd0d4ccf1e.tar.gz
chromium_src-31c406b1b4fe7b0060fab563040bd3cd0d4ccf1e.tar.bz2
Remove static initializers from Spdy code.
Note that max() from numeric_limits<> is not evaluated at compile time. This seems to be true at least with GCC. BUG=94925 Review URL: http://codereview.chromium.org/9416045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127451 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/spdy/spdy_frame_builder.cc3
-rw-r--r--net/spdy/spdy_framer.cc25
2 files changed, 17 insertions, 11 deletions
diff --git a/net/spdy/spdy_frame_builder.cc b/net/spdy/spdy_frame_builder.cc
index e857d90..2948b3c 100644
--- a/net/spdy/spdy_frame_builder.cc
+++ b/net/spdy/spdy_frame_builder.cc
@@ -9,9 +9,6 @@
namespace spdy {
-// We mark a read only SpdyFrameBuilder with a special capacity_.
-static const size_t kCapacityReadOnly = std::numeric_limits<size_t>::max();
-
SpdyFrameBuilder::SpdyFrameBuilder(size_t size)
: buffer_(NULL),
capacity_(0),
diff --git a/net/spdy/spdy_framer.cc b/net/spdy/spdy_framer.cc
index ccf7d26..32415e1 100644
--- a/net/spdy/spdy_framer.cc
+++ b/net/spdy/spdy_framer.cc
@@ -8,6 +8,7 @@
#include "net/spdy/spdy_framer.h"
+#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/stats_counters.h"
#include "base/third_party/valgrind/memcheck.h"
@@ -35,11 +36,18 @@ uLong CalculateDictionaryId(const char* dictionary,
dictionary_size);
}
-// Adler ID for the SPDY header compressor dictionaries.
-const uLong kV2DictionaryId = CalculateDictionaryId(kV2Dictionary,
- kV2DictionarySize);
-const uLong kV3DictionaryId = CalculateDictionaryId(kV3Dictionary,
- kV3DictionarySize);
+struct DictionaryIds {
+ DictionaryIds()
+ : v2_dictionary_id(CalculateDictionaryId(kV2Dictionary, kV2DictionarySize)),
+ v3_dictionary_id(CalculateDictionaryId(kV3Dictionary, kV3DictionarySize))
+ {}
+ const uLong v2_dictionary_id;
+ const uLong v3_dictionary_id;
+};
+
+// Adler ID for the SPDY header compressor dictionaries. Note that they are
+// initialized lazily to avoid static initializers.
+base::LazyInstance<DictionaryIds>::Leaky g_dictionary_ids;
// Creates a FlagsAndLength.
FlagsAndLength CreateFlagsAndLength(SpdyControlFlags flags, size_t length) {
@@ -1571,11 +1579,12 @@ bool SpdyFramer::IncrementallyDecompressControlFrameHeaderData(
int rv = inflate(decomp, Z_SYNC_FLUSH);
if (rv == Z_NEED_DICT) {
const char* dictionary = (spdy_version_ < 3) ? kV2Dictionary
- : kV3Dictionary;
+ : kV3Dictionary;
const int dictionary_size = (spdy_version_ < 3) ? kV2DictionarySize
: kV3DictionarySize;
- const uLong dictionary_id = (spdy_version_ < 3) ? kV2DictionaryId
- : kV3DictionaryId;
+ const DictionaryIds& ids = g_dictionary_ids.Get();
+ const uLong dictionary_id = (spdy_version_ < 3) ? ids.v2_dictionary_id
+ : ids.v3_dictionary_id;
// Need to try again with the right dictionary.
if (decomp->adler == dictionary_id) {
rv = inflateSetDictionary(decomp,