Don't bother with 16-bit reference count and index in nsCSSValue::Array. (Bug 574059) r=bzbarsky

This commit is contained in:
L. David Baron 2010-06-24 14:53:44 -07:00
parent 9f0610f3db
commit 736090d613
3 changed files with 16 additions and 16 deletions

View File

@ -1755,7 +1755,7 @@ InsertFontFaceRule(nsCSSFontFaceRule *aRule, gfxUserFontSet* aFontSet,
unit = val.GetUnit();
if (unit == eCSSUnit_Array) {
nsCSSValue::Array *srcArr = val.GetArrayValue();
PRUint32 i, numSrc = srcArr->Count();
size_t i, numSrc = srcArr->Count();
for (i = 0; i < numSrc; i++) {
val = srcArr->Item(i);

View File

@ -126,7 +126,7 @@ ComputeCalc(const nsCSSValue& aValue, CalcOps &aOps)
case eCSSUnit_Calc_Maximum: {
nsCSSValue::Array *arr = aValue.GetArrayValue();
typename CalcOps::result_type result = ComputeCalc(arr->Item(0), aOps);
for (PRUint32 i = 1, i_end = arr->Count(); i < i_end; ++i) {
for (size_t i = 1, i_end = arr->Count(); i < i_end; ++i) {
typename CalcOps::result_type tmp = ComputeCalc(arr->Item(i), aOps);
result = aOps.MergeAdditive(aValue.GetUnit(), result, tmp);
}

View File

@ -527,39 +527,39 @@ private:
struct nsCSSValue::Array {
// return |Array| with reference count of zero
static Array* Create(PRUint16 aItemCount) {
static Array* Create(size_t aItemCount) {
return new (aItemCount) Array(aItemCount);
}
nsCSSValue& operator[](PRUint16 aIndex) {
nsCSSValue& operator[](size_t aIndex) {
NS_ASSERTION(aIndex < mCount, "out of range");
return mArray[aIndex];
}
const nsCSSValue& operator[](PRUint16 aIndex) const {
const nsCSSValue& operator[](size_t aIndex) const {
NS_ASSERTION(aIndex < mCount, "out of range");
return mArray[aIndex];
}
nsCSSValue& Item(PRUint16 aIndex) { return (*this)[aIndex]; }
const nsCSSValue& Item(PRUint16 aIndex) const { return (*this)[aIndex]; }
nsCSSValue& Item(size_t aIndex) { return (*this)[aIndex]; }
const nsCSSValue& Item(size_t aIndex) const { return (*this)[aIndex]; }
PRUint16 Count() const { return mCount; }
size_t Count() const { return mCount; }
PRBool operator==(const Array& aOther) const
{
if (mCount != aOther.mCount)
return PR_FALSE;
for (PRUint16 i = 0; i < mCount; ++i)
for (size_t i = 0; i < mCount; ++i)
if ((*this)[i] != aOther[i])
return PR_FALSE;
return PR_TRUE;
}
// XXXdholbert This uses a 16-bit ref count to save space. Should we use
// XXXdholbert This uses a size_t ref count to save space. Should we use
// a variant of NS_INLINE_DECL_REFCOUNTING that takes a type as an argument?
void AddRef() {
if (mRefCnt == PR_UINT16_MAX) {
if (mRefCnt == size_t(-1)) { // really want SIZE_MAX
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
return;
}
@ -567,7 +567,7 @@ struct nsCSSValue::Array {
NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
}
void Release() {
if (mRefCnt == PR_UINT16_MAX) {
if (mRefCnt == size_t(-1)) { // really want SIZE_MAX
NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
return;
}
@ -579,14 +579,14 @@ struct nsCSSValue::Array {
private:
PRUint16 mRefCnt;
const PRUint16 mCount;
size_t mRefCnt;
const size_t mCount;
// This must be the last sub-object, since we extend this array to
// be of size mCount; it needs to be a sub-object so it gets proper
// alignment.
nsCSSValue mArray[1];
void* operator new(size_t aSelfSize, PRUint16 aItemCount) CPP_THROW_NEW {
void* operator new(size_t aSelfSize, size_t aItemCount) CPP_THROW_NEW {
NS_ABORT_IF_FALSE(aItemCount > 0, "cannot have a 0 item count");
return ::operator new(aSelfSize + sizeof(nsCSSValue) * (aItemCount - 1));
}
@ -601,7 +601,7 @@ private:
for (nsCSSValue *var = First() + 1, *var##_end = First() + mCount; \
var != var##_end; ++var)
Array(PRUint16 aItemCount)
Array(size_t aItemCount)
: mRefCnt(0)
, mCount(aItemCount)
{