Reduced the number of nsString objects allocated
This commit is contained in:
troy%netscape.com 2000-02-23 15:45:43 +00:00
Родитель fef9747403
Коммит 2cab23cc6c
6 изменённых файлов: 128 добавлений и 18 удалений

Просмотреть файл

@ -1220,8 +1220,9 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
return NS_CONTENT_ATTR_NOT_THERE;
}
nsHTMLValue value;
nsresult result = GetHTMLAttribute(aAttribute, value);
const nsHTMLValue* value;
nsresult result = mAttributes ? mAttributes->GetAttribute(aAttribute, &value) :
NS_CONTENT_ATTR_NOT_THERE;
char cbuf[20];
nscolor color;
@ -1233,14 +1234,14 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
}
// Try subclass conversion routine first
if (NS_CONTENT_ATTR_HAS_VALUE ==
htmlContent->AttributeToString(aAttribute, value, aResult)) {
htmlContent->AttributeToString(aAttribute, *value, aResult)) {
NS_RELEASE(htmlContent);
return result;
}
NS_RELEASE(htmlContent);
// Provide default conversions for most everything
switch (value.GetUnit()) {
switch (value->GetUnit()) {
case eHTMLUnit_Null:
case eHTMLUnit_Empty:
aResult.Truncate();
@ -1248,27 +1249,27 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
case eHTMLUnit_String:
case eHTMLUnit_ColorName:
value.GetStringValue(aResult);
value->GetStringValue(aResult);
break;
case eHTMLUnit_Integer:
aResult.Truncate();
aResult.Append(value.GetIntValue(), 10);
aResult.Append(value->GetIntValue(), 10);
break;
case eHTMLUnit_Pixel:
aResult.Truncate();
aResult.Append(value.GetPixelValue(), 10);
aResult.Append(value->GetPixelValue(), 10);
break;
case eHTMLUnit_Percent:
aResult.Truncate();
aResult.Append(PRInt32(value.GetPercentValue() * 100.0f), 10);
aResult.Append(PRInt32(value->GetPercentValue() * 100.0f), 10);
aResult.Append('%');
break;
case eHTMLUnit_Color:
color = nscolor(value.GetColorValue());
color = nscolor(value->GetColorValue());
PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
NS_GET_R(color), NS_GET_G(color), NS_GET_B(color));
aResult.Truncate();
@ -1282,6 +1283,7 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
break;
}
}
return result;
}

Просмотреть файл

@ -294,6 +294,8 @@ public:
NS_IMETHOD GetAttribute(nsIAtom* aAttrName,
nsHTMLValue& aValue) const;
NS_IMETHOD GetAttribute(nsIAtom* aAttrName,
const nsHTMLValue** aValue) const;
NS_IMETHOD GetAttributeCount(PRInt32& aCount) const;
@ -593,6 +595,25 @@ nsHTMLMappedAttributes::GetAttribute(nsIAtom* aAttrName,
return NS_CONTENT_ATTR_NOT_THERE;
}
NS_IMETHODIMP
nsHTMLMappedAttributes::GetAttribute(nsIAtom* aAttrName,
const nsHTMLValue** aValue) const
{
if (! aAttrName) {
return NS_ERROR_NULL_POINTER;
}
const HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, &mFirst);
if (attr) {
*aValue = &attr->mValue;
return ((attr->mValue.GetUnit() == eHTMLUnit_Null) ?
NS_CONTENT_ATTR_NO_VALUE :
NS_CONTENT_ATTR_HAS_VALUE);
}
*aValue = nsnull;
return NS_CONTENT_ATTR_NOT_THERE;
}
NS_IMETHODIMP
nsHTMLMappedAttributes::GetAttributeCount(PRInt32& aCount) const
{
@ -794,6 +815,8 @@ public:
NS_IMETHOD GetAttribute(nsIAtom* aAttrName,
nsHTMLValue& aValue) const;
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
const nsHTMLValue** aValue) const;
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex,
nsIAtom*& aName) const;
@ -1290,6 +1313,33 @@ HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName,
return result;
}
NS_IMETHODIMP
HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName,
const nsHTMLValue** aValue) const
{
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
if (mMapped) {
result = mMapped->GetAttribute(aAttrName, aValue);
}
if (NS_CONTENT_ATTR_NOT_THERE == result) {
const HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, mFirstUnmapped);
if (attr) {
*aValue = &attr->mValue;
result = ((attr->mValue.GetUnit() == eHTMLUnit_Null) ?
NS_CONTENT_ATTR_NO_VALUE :
NS_CONTENT_ATTR_HAS_VALUE);
}
else {
*aValue = nsnull;
}
}
return result;
}
NS_IMETHODIMP
HTMLAttributesImpl::GetAttributeNameAt(PRInt32 aIndex,
nsIAtom*& aName) const

Просмотреть файл

@ -63,6 +63,8 @@ public:
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
nsHTMLValue& aValue) const = 0;
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
const nsHTMLValue** aValue) const = 0;
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex,
nsIAtom*& aName) const = 0;
@ -100,6 +102,7 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_MAPPED_ATTRIBUTES_IID);
NS_IMETHOD GetAttribute(nsIAtom* aAttrName, nsHTMLValue& aValue) const = 0;
NS_IMETHOD GetAttribute(nsIAtom* aAttrName, const nsHTMLValue** aValue) const = 0;
NS_IMETHOD GetAttributeCount(PRInt32& aCount) const = 0;
NS_IMETHOD Equals(const nsIHTMLMappedAttributes* aAttributes, PRBool& aResult) const = 0;

Просмотреть файл

@ -1220,8 +1220,9 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
return NS_CONTENT_ATTR_NOT_THERE;
}
nsHTMLValue value;
nsresult result = GetHTMLAttribute(aAttribute, value);
const nsHTMLValue* value;
nsresult result = mAttributes ? mAttributes->GetAttribute(aAttribute, &value) :
NS_CONTENT_ATTR_NOT_THERE;
char cbuf[20];
nscolor color;
@ -1233,14 +1234,14 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
}
// Try subclass conversion routine first
if (NS_CONTENT_ATTR_HAS_VALUE ==
htmlContent->AttributeToString(aAttribute, value, aResult)) {
htmlContent->AttributeToString(aAttribute, *value, aResult)) {
NS_RELEASE(htmlContent);
return result;
}
NS_RELEASE(htmlContent);
// Provide default conversions for most everything
switch (value.GetUnit()) {
switch (value->GetUnit()) {
case eHTMLUnit_Null:
case eHTMLUnit_Empty:
aResult.Truncate();
@ -1248,27 +1249,27 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
case eHTMLUnit_String:
case eHTMLUnit_ColorName:
value.GetStringValue(aResult);
value->GetStringValue(aResult);
break;
case eHTMLUnit_Integer:
aResult.Truncate();
aResult.Append(value.GetIntValue(), 10);
aResult.Append(value->GetIntValue(), 10);
break;
case eHTMLUnit_Pixel:
aResult.Truncate();
aResult.Append(value.GetPixelValue(), 10);
aResult.Append(value->GetPixelValue(), 10);
break;
case eHTMLUnit_Percent:
aResult.Truncate();
aResult.Append(PRInt32(value.GetPercentValue() * 100.0f), 10);
aResult.Append(PRInt32(value->GetPercentValue() * 100.0f), 10);
aResult.Append('%');
break;
case eHTMLUnit_Color:
color = nscolor(value.GetColorValue());
color = nscolor(value->GetColorValue());
PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
NS_GET_R(color), NS_GET_G(color), NS_GET_B(color));
aResult.Truncate();
@ -1282,6 +1283,7 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
break;
}
}
return result;
}

Просмотреть файл

@ -294,6 +294,8 @@ public:
NS_IMETHOD GetAttribute(nsIAtom* aAttrName,
nsHTMLValue& aValue) const;
NS_IMETHOD GetAttribute(nsIAtom* aAttrName,
const nsHTMLValue** aValue) const;
NS_IMETHOD GetAttributeCount(PRInt32& aCount) const;
@ -593,6 +595,25 @@ nsHTMLMappedAttributes::GetAttribute(nsIAtom* aAttrName,
return NS_CONTENT_ATTR_NOT_THERE;
}
NS_IMETHODIMP
nsHTMLMappedAttributes::GetAttribute(nsIAtom* aAttrName,
const nsHTMLValue** aValue) const
{
if (! aAttrName) {
return NS_ERROR_NULL_POINTER;
}
const HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, &mFirst);
if (attr) {
*aValue = &attr->mValue;
return ((attr->mValue.GetUnit() == eHTMLUnit_Null) ?
NS_CONTENT_ATTR_NO_VALUE :
NS_CONTENT_ATTR_HAS_VALUE);
}
*aValue = nsnull;
return NS_CONTENT_ATTR_NOT_THERE;
}
NS_IMETHODIMP
nsHTMLMappedAttributes::GetAttributeCount(PRInt32& aCount) const
{
@ -794,6 +815,8 @@ public:
NS_IMETHOD GetAttribute(nsIAtom* aAttrName,
nsHTMLValue& aValue) const;
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
const nsHTMLValue** aValue) const;
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex,
nsIAtom*& aName) const;
@ -1290,6 +1313,33 @@ HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName,
return result;
}
NS_IMETHODIMP
HTMLAttributesImpl::GetAttribute(nsIAtom* aAttrName,
const nsHTMLValue** aValue) const
{
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
if (mMapped) {
result = mMapped->GetAttribute(aAttrName, aValue);
}
if (NS_CONTENT_ATTR_NOT_THERE == result) {
const HTMLAttribute* attr = HTMLAttribute::FindHTMLAttribute(aAttrName, mFirstUnmapped);
if (attr) {
*aValue = &attr->mValue;
result = ((attr->mValue.GetUnit() == eHTMLUnit_Null) ?
NS_CONTENT_ATTR_NO_VALUE :
NS_CONTENT_ATTR_HAS_VALUE);
}
else {
*aValue = nsnull;
}
}
return result;
}
NS_IMETHODIMP
HTMLAttributesImpl::GetAttributeNameAt(PRInt32 aIndex,
nsIAtom*& aName) const

Просмотреть файл

@ -63,6 +63,8 @@ public:
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
nsHTMLValue& aValue) const = 0;
NS_IMETHOD GetAttribute(nsIAtom* aAttribute,
const nsHTMLValue** aValue) const = 0;
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex,
nsIAtom*& aName) const = 0;
@ -100,6 +102,7 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTML_MAPPED_ATTRIBUTES_IID);
NS_IMETHOD GetAttribute(nsIAtom* aAttrName, nsHTMLValue& aValue) const = 0;
NS_IMETHOD GetAttribute(nsIAtom* aAttrName, const nsHTMLValue** aValue) const = 0;
NS_IMETHOD GetAttributeCount(PRInt32& aCount) const = 0;
NS_IMETHOD Equals(const nsIHTMLMappedAttributes* aAttributes, PRBool& aResult) const = 0;