You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/06/08 16:04:01 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime AbstractTranslet.java BasisLibrary.java
santiagopg 2002/06/08 07:04:01
Modified: java/src/org/apache/xalan/xsltc/runtime
AbstractTranslet.java BasisLibrary.java
Log:
Fixed memory leak in AbstractTranslet and moved replace() method
to BasisLibrary.
Revision Changes Path
1.37 +31 -37 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java
Index: AbstractTranslet.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/AbstractTranslet.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- AbstractTranslet.java 21 May 2002 15:13:25 -0000 1.36
+++ AbstractTranslet.java 8 Jun 2002 14:04:00 -0000 1.37
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: AbstractTranslet.java,v 1.36 2002/05/21 15:13:25 santiagopg Exp $
+ * @(#)$Id: AbstractTranslet.java,v 1.37 2002/06/08 14:04:00 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
@@ -103,6 +103,25 @@
// Use one empty string instead of constantly instanciating String("");
private final static String EMPTYSTRING = "";
+
+ /************************************************************************
+ * Debugging
+ ************************************************************************/
+ public void printInternalState() {
+ System.out.println("-------------------------------------");
+ System.out.println("AbstractTranslet this = " + this);
+ System.out.println("vbase = " + vbase);
+ System.out.println("vframe = " + vframe);
+ System.out.println("varsStack.size() = " + varsStack.size());
+ System.out.println("pbase = " + pbase);
+ System.out.println("vframe = " + pframe);
+ System.out.println("paramsStack.size() = " + paramsStack.size());
+ System.out.println("namesArray.size = " + namesArray.length);
+ System.out.println("namespaceArray.size = " + namespaceArray.length);
+ System.out.println("");
+ System.out.println("Total memory = " + Runtime.getRuntime().totalMemory());
+ }
+
/**
* Wrap the initial input DOM in a dom adapter. This adapter is wrapped in
* a DOM multiplexer if the document() function is used (handled by compiled
@@ -144,8 +163,8 @@
public final void popParamFrame() {
if (pbase > 0) {
final int oldpbase = ((Integer)paramsStack.get(--pbase)).intValue();
- for (int i = pbase; i < pframe; i++) {
- paramsStack.set(i, null); // for the GC
+ for (int i = pframe - 1; i >= pbase; i--) {
+ paramsStack.remove(i);
}
pframe = pbase; pbase = oldpbase;
}
@@ -155,10 +174,9 @@
* Add a new global parameter if not already in the current frame.
*/
public final Object addParameter(String name, Object value) {
- String parName = new String(name);
- parName = replace(parName, '.', "$dot$");
- parName = replace(parName, '-', "$dash$");
- return addParameter(parName, value, false);
+ name = BasisLibrary.replace(name, ".-",
+ new String[] { "$dot$", "$dash$" });
+ return addParameter(name, value, false);
}
/**
@@ -167,16 +185,17 @@
* default value from the <xsl:parameter> element's select attribute or
* element body.
*/
- public final Object addParameter(String name, Object value,
- boolean isDefault) {
-
+ public final Object addParameter(String name, Object value,
+ boolean isDefault)
+ {
// Local parameters need to be re-evaluated for each iteration
for (int i = pframe - 1; i >= pbase; i--) {
final Parameter param = (Parameter) paramsStack.get(i);
+
if (param._name.equals(name)) {
// Only overwrite if current value is the default value and
// the new value is _NOT_ the default value.
- if ((param._isDefault == true) || (!isDefault)) {
+ if (param._isDefault || !isDefault) {
param._value = value;
param._isDefault = isDefault;
return value;
@@ -186,8 +205,7 @@
}
// Add new parameter to parameter stack
- final Parameter param = new Parameter(name, value, isDefault);
- paramsStack.add(pframe++, param);
+ paramsStack.add(pframe++, new Parameter(name, value, isDefault));
return value;
}
@@ -250,30 +268,6 @@
*/
public final void addVariable(int vindex, Object value) {
varsStack.set(vbase + vindex, value);
- }
-
- /**
- * Replace a certain character in a string with a new substring.
- */
- private static String replace(String base, char c, String str) {
- final int len = base.length() - 1;
- int pos;
- while ((pos = base.indexOf(c)) > -1) {
- if (pos == 0) {
- final String after = base.substring(1);
- base = str + after;
- }
- else if (pos == len) {
- final String before = base.substring(0, pos);
- base = before + str;
- }
- else {
- final String before = base.substring(0, pos);
- final String after = base.substring(pos+1);
- base = before + str + after;
- }
- }
- return base;
}
/************************************************************************
1.40 +27 -1 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
Index: BasisLibrary.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- BasisLibrary.java 5 Jun 2002 20:23:14 -0000 1.39
+++ BasisLibrary.java 8 Jun 2002 14:04:00 -0000 1.40
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: BasisLibrary.java,v 1.39 2002/06/05 20:23:14 tmiller Exp $
+ * @(#)$Id: BasisLibrary.java,v 1.40 2002/06/08 14:04:00 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
@@ -1073,6 +1073,32 @@
public static void consoleOutput(String msg) {
System.out.println(msg);
+ }
+
+ /**
+ * Replace a certain character in a string with a new substring.
+ */
+ public static String replace(String base, char ch, String str) {
+ return (base.indexOf(ch) < 0) ? base :
+ replace(base, String.valueOf(ch), new String[] { str });
+ }
+
+ public static String replace(String base, String delim, String[] str) {
+ final int len = base.length();
+ final StringBuffer result = new StringBuffer();
+
+ for (int i = 0; i < len; i++) {
+ final char ch = base.charAt(i);
+ final int k = delim.indexOf(ch);
+
+ if (k >= 0) {
+ result.append(str[k]);
+ }
+ else {
+ result.append(ch);
+ }
+ }
+ return result.toString();
}
//-- End utility functions
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org