layout/style/nsRuleData.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsRuleData.h"
michael@0 7
michael@0 8 #include "mozilla/Poison.h"
michael@0 9 #include <stdint.h>
michael@0 10
michael@0 11 inline size_t
michael@0 12 nsRuleData::GetPoisonOffset()
michael@0 13 {
michael@0 14 // Fill in mValueOffsets such that mValueStorage + mValueOffsets[i]
michael@0 15 // will yield the frame poison value for all uninitialized value
michael@0 16 // offsets.
michael@0 17 static_assert(sizeof(uintptr_t) == sizeof(size_t),
michael@0 18 "expect uintptr_t and size_t to be the same size");
michael@0 19 static_assert(uintptr_t(-1) > uintptr_t(0),
michael@0 20 "expect uintptr_t to be unsigned");
michael@0 21 static_assert(size_t(-1) > size_t(0),
michael@0 22 "expect size_t to be unsigned");
michael@0 23 uintptr_t framePoisonValue = mozPoisonValue();
michael@0 24 return size_t(framePoisonValue - uintptr_t(mValueStorage)) /
michael@0 25 sizeof(nsCSSValue);
michael@0 26 }
michael@0 27
michael@0 28 nsRuleData::nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage,
michael@0 29 nsPresContext* aContext, nsStyleContext* aStyleContext)
michael@0 30 : mSIDs(aSIDs),
michael@0 31 mCanStoreInRuleTree(true),
michael@0 32 mPresContext(aContext),
michael@0 33 mStyleContext(aStyleContext),
michael@0 34 mValueStorage(aValueStorage)
michael@0 35 {
michael@0 36 #ifndef MOZ_VALGRIND
michael@0 37 size_t framePoisonOffset = GetPoisonOffset();
michael@0 38 for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
michael@0 39 mValueOffsets[i] = framePoisonOffset;
michael@0 40 }
michael@0 41 #endif
michael@0 42 }
michael@0 43
michael@0 44 #ifdef DEBUG
michael@0 45 nsRuleData::~nsRuleData()
michael@0 46 {
michael@0 47 #ifndef MOZ_VALGRIND
michael@0 48 // assert nothing in mSIDs has poison value
michael@0 49 size_t framePoisonOffset = GetPoisonOffset();
michael@0 50 for (size_t i = 0; i < nsStyleStructID_Length; ++i) {
michael@0 51 NS_ABORT_IF_FALSE(!(mSIDs & (1 << i)) ||
michael@0 52 mValueOffsets[i] != framePoisonOffset,
michael@0 53 "value in SIDs was left with poison offset");
michael@0 54 }
michael@0 55 #endif
michael@0 56 }
michael@0 57 #endif

mercurial