From 35c78734e80c8c2e326ccfb514793c4599390dfa Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 26 Nov 2001 17:33:02 +0000 Subject: [PATCH] added a clearCache() function to the HopObject prototype that lets one clear (recreate) the HopObject's cache node. createSkin now uses the application's skin cache. This is not really much faster because caching and skin creation are very similar in speed, but it should help reduce garbage collection. --- src/helma/scripting/fesi/HopExtension.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/helma/scripting/fesi/HopExtension.java b/src/helma/scripting/fesi/HopExtension.java index 0c6383dc..4da9acae 100644 --- a/src/helma/scripting/fesi/HopExtension.java +++ b/src/helma/scripting/fesi/HopExtension.java @@ -82,8 +82,9 @@ public class HopExtension { reval.esNodePrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp)); reval.esNodePrototype.putHiddenProperty ("setParent", new NodeSetParent ("setParent", evaluator, fp)); reval.esNodePrototype.putHiddenProperty ("invalidate", new NodeInvalidate ("invalidate", evaluator, fp)); - reval.esNodePrototype.putHiddenProperty("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false)); - reval.esNodePrototype.putHiddenProperty("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true)); + reval.esNodePrototype.putHiddenProperty ("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, false, false)); + reval.esNodePrototype.putHiddenProperty ("renderSkinAsString", new RenderSkin ("renderSkinAsString", evaluator, fp, false, true)); + reval.esNodePrototype.putHiddenProperty ("clearCache", new NodeClearCache ("clearCache", evaluator, fp)); // default methods for generic Java wrapper object prototype reval.esObjectPrototype.putHiddenProperty ("href", new NodeHref ("href", evaluator, fp)); @@ -557,7 +558,11 @@ public class HopExtension { if (arguments.length != 1 || ESNull.theNull.equals (arguments[0])) throw new EcmaScriptException ("createSkin must be called with one String argument"); String str = arguments[0].toString (); - Skin skin = new Skin (str, app); + Skin skin = (Skin) app.skincache.get (str); + if (skin == null) { + skin = new Skin (str, app); + app.skincache.put (str, skin); + } return new ESWrapper (skin, evaluator); } } @@ -943,6 +948,15 @@ public class HopExtension { } } + class NodeClearCache extends BuiltinFunctionObject { + NodeClearCache (String name, Evaluator evaluator, FunctionPrototype fp) { + super (fp, evaluator, name, 2); + } + public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException { + ESNode node = (ESNode) thisObject; + return ESBoolean.makeBoolean (node.clearCache ()); + } + } class NodeHref extends BuiltinFunctionObject { NodeHref (String name, Evaluator evaluator, FunctionPrototype fp) {