From cfde75b236e3829235043e1edbc06d9f7f198cc0 Mon Sep 17 00:00:00 2001 From: "cst%yecc.com" Date: Tue, 6 Jun 2006 13:26:26 +0000 Subject: [PATCH] Bug 258058 nsValueArray needs a ReplaceValueAt() r=bsmedberg sr=alecf git-svn-id: svn://10.0.0.236/trunk@199104 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsValueArray.cpp | 33 ++++++++++++++++++++++++++++++- mozilla/xpcom/ds/nsValueArray.h | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mozilla/xpcom/ds/nsValueArray.cpp b/mozilla/xpcom/ds/nsValueArray.cpp index 4660cceca9f..6ac9d90cf07 100644 --- a/mozilla/xpcom/ds/nsValueArray.cpp +++ b/mozilla/xpcom/ds/nsValueArray.cpp @@ -199,7 +199,7 @@ PRBool nsValueArray::InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex a NS_ASSERTION(*((PRUint32*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!"); break; default: - NS_ASSERTION(0, "surely you've been warned prior to this!"); + NS_ERROR("surely you've been warned prior to this!"); break; } @@ -213,6 +213,37 @@ PRBool nsValueArray::InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex a return retval; } +// +// Replace the item at aIndex with aValue +// No validity checking other than index is done. +// +PRBool nsValueArray::ReplaceValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex) { + NS_ENSURE_TRUE(aIndex < Count(), PR_FALSE); + + // + // Do the assignment. + // + switch (mBytesPerValue) { + case sizeof(PRUint8): + *((PRUint8*)&mValueArray[aIndex * mBytesPerValue]) = (PRUint8)aValue; + NS_ASSERTION(*((PRUint8*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!"); + break; + case sizeof(PRUint16): + *((PRUint16*)&mValueArray[aIndex * mBytesPerValue]) = (PRUint16)aValue; + NS_ASSERTION(*((PRUint16*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!"); + break; + case sizeof(PRUint32): + *((PRUint32*)&mValueArray[aIndex * mBytesPerValue]) = (PRUint32)aValue; + NS_ASSERTION(*((PRUint32*)&mValueArray[aIndex * mBytesPerValue]) == aValue, "Lossy value array detected. Report a higher maximum upon construction!"); + break; + default: + NS_ERROR("surely you've been warned prior to this!"); + break; + } + + return PR_TRUE; +} + // // Remove the index from the value array. // The array does not shrink until Compact() is invoked. diff --git a/mozilla/xpcom/ds/nsValueArray.h b/mozilla/xpcom/ds/nsValueArray.h index 6437ca607de..cc2a6006022 100644 --- a/mozilla/xpcom/ds/nsValueArray.h +++ b/mozilla/xpcom/ds/nsValueArray.h @@ -110,6 +110,8 @@ class NS_COM nsValueArray { PRBool InsertValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex); + PRBool ReplaceValueAt(nsValueArrayValue aValue, nsValueArrayIndex aIndex); + PRBool RemoveValueAt(nsValueArrayIndex aIndex); //