From 9ed3838a87bc617a7119df4eee47ea6f6f27bc19 Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Sat, 2 Feb 2008 22:11:12 +0000 Subject: [PATCH] Further improvement in FixedLength: * added a special ZERO_FIXED_LENGTH instance * store only non-zero values in the PropertyCache git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@617907 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/properties/BorderWidthPropertyMaker.java | 2 +- src/java/org/apache/fop/fo/properties/FixedLength.java | 9 ++++++++- .../apache/fop/fo/properties/IndentPropertyMaker.java | 6 +++--- .../apache/fop/fo/properties/LengthRangeProperty.java | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java b/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java index 86986bca5..341baca1a 100644 --- a/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/BorderWidthPropertyMaker.java @@ -63,7 +63,7 @@ public class BorderWidthPropertyMaker extends LengthProperty.Maker { // Calculate the values as described in 7.7.20. Property style = propertyList.get(borderStyleId); if (style.getEnum() == Constants.EN_NONE) { - return FixedLength.getInstance(0); + return FixedLength.ZERO_FIXED_LENGTH; } return p; } diff --git a/src/java/org/apache/fop/fo/properties/FixedLength.java b/src/java/org/apache/fop/fo/properties/FixedLength.java index fbd235b30..7c4344b53 100644 --- a/src/java/org/apache/fop/fo/properties/FixedLength.java +++ b/src/java/org/apache/fop/fo/properties/FixedLength.java @@ -29,6 +29,9 @@ public final class FixedLength extends LengthProperty { /** cache holding all canonical FixedLength instances */ private static final PropertyCache cache = new PropertyCache(); + /** canonical zero-length instance */ + public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, "mpt", 1.0f); + private int millipoints; /** @@ -57,8 +60,12 @@ public final class FixedLength extends LengthProperty { public static FixedLength getInstance(double numUnits, String units, float sourceResolution) { - return (FixedLength)cache.fetch( + if (numUnits == 0.0) { + return ZERO_FIXED_LENGTH; + } else { + return (FixedLength)cache.fetch( new FixedLength(numUnits, units, sourceResolution)); + } } diff --git a/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java b/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java index b29caba04..75ecb9d24 100644 --- a/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java @@ -108,7 +108,7 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker { //Margin is used Numeric margin = propertyList.get(marginProp).getNumeric(); - Numeric v = FixedLength.getInstance(0, "mpt"); + Numeric v = FixedLength.ZERO_FIXED_LENGTH; if (!propertyList.getFObj().generatesReferenceAreas()) { // The inherited_value_of([start|end]-indent) v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric()); @@ -173,7 +173,7 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker { if (isInherited(propertyList) || !marginNearest) { return null; } else { - return FixedLength.getInstance(0); + return FixedLength.ZERO_FIXED_LENGTH; } } else { return indent; @@ -182,7 +182,7 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker { //Margin is used Numeric margin = propertyList.get(marginProp).getNumeric(); - Numeric v = FixedLength.getInstance(0); + Numeric v = FixedLength.ZERO_FIXED_LENGTH; if (isInherited(propertyList)) { // The inherited_value_of([start|end]-indent) v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric()); diff --git a/src/java/org/apache/fop/fo/properties/LengthRangeProperty.java b/src/java/org/apache/fop/fo/properties/LengthRangeProperty.java index 966f51a51..aeab37972 100644 --- a/src/java/org/apache/fop/fo/properties/LengthRangeProperty.java +++ b/src/java/org/apache/fop/fo/properties/LengthRangeProperty.java @@ -82,7 +82,7 @@ public class LengthRangeProperty extends Property implements CompoundDatatype { log.warn(FObj.decorateWithContextInfo( "Replaced negative value (" + len + ") for " + getName() + " with 0mpt", fo)); - p = FixedLength.getInstance(0); + p = FixedLength.ZERO_FIXED_LENGTH; } } } @@ -105,7 +105,7 @@ public class LengthRangeProperty extends Property implements CompoundDatatype { log.warn("Replaced negative value (" + len + ") for " + getName() + " with 0mpt"); val.setComponent(subpropertyId, - FixedLength.getInstance(0), false); + FixedLength.ZERO_FIXED_LENGTH, false); return baseProperty; } } -- 2.39.5