Bug 473517. nsSVGUtils::CoordToFloat should avoid heap-allocating an nsSVGLength. r+sr=roc

--HG--
extra : rebase_source : c2cd532376da8c37ad02f834ab4e859fec61dda1
This commit is contained in:
Craig Topper 2009-01-16 21:02:40 +13:00
Родитель 1cf2f409ec
Коммит dc0c2a207d
1 изменённых файлов: 5 добавлений и 23 удалений

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

@ -34,7 +34,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsSVGLength.h"
#include "nsIDOMDocument.h"
#include "nsIDOMSVGElement.h"
#include "nsIDOMSVGSVGElement.h"
@ -364,38 +363,21 @@ nsSVGUtils::CoordToFloat(nsPresContext *aPresContext,
nsSVGElement *aContent,
const nsStyleCoord &aCoord)
{
float val = 0.0f;
switch (aCoord.GetUnit()) {
case eStyleUnit_Factor:
// user units
val = aCoord.GetFactorValue();
break;
return aCoord.GetFactorValue();
case eStyleUnit_Coord:
val = nsPresContext::AppUnitsToFloatCSSPixels(aCoord.GetCoordValue());
break;
return nsPresContext::AppUnitsToFloatCSSPixels(aCoord.GetCoordValue());
case eStyleUnit_Percent: {
nsCOMPtr<nsISVGLength> length;
NS_NewSVGLength(getter_AddRefs(length),
aCoord.GetPercentValue() * 100.0f,
nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE);
if (!length)
break;
nsWeakPtr weakCtx =
do_GetWeakReference(static_cast<nsGenericElement*>(aContent));
length->SetContext(weakCtx, nsSVGUtils::XY);
length->GetValue(&val);
break;
nsSVGSVGElement* ctx = aContent->GetCtx();
return ctx ? aCoord.GetPercentValue() * ctx->GetLength(nsSVGUtils::XY) : 0.0f;
}
default:
break;
return 0.0f;
}
return val;
}
nsresult