From: <k_s...@us...> - 2008-08-12 18:31:42
|
Revision: 13283 http://jedit.svn.sourceforge.net/jedit/?rev=13283&view=rev Author: k_satoda Date: 2008-08-12 18:31:39 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Eliminated needless references to Buffer from KillRing, which often held closed buffers in memory after editing. The actual path was KillRing.ring -> UndoManager.Remove.mgr -> UndoManager.buffer. jProfiler helped. Modified Paths: -------------- jEdit/trunk/doc/CHANGES.txt jEdit/trunk/org/gjt/sp/jedit/buffer/KillRing.java jEdit/trunk/org/gjt/sp/jedit/buffer/UndoManager.java Modified: jEdit/trunk/doc/CHANGES.txt =================================================================== --- jEdit/trunk/doc/CHANGES.txt 2008-08-12 18:30:14 UTC (rev 13282) +++ jEdit/trunk/doc/CHANGES.txt 2008-08-12 18:31:39 UTC (rev 13283) @@ -6,6 +6,7 @@ {{{ Bug Fixes +- Closed buffers were often kept in memory. (Kazutoshi Satoda) }}} {{{ Miscellaneous Modified: jEdit/trunk/org/gjt/sp/jedit/buffer/KillRing.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/buffer/KillRing.java 2008-08-12 18:30:14 UTC (rev 13282) +++ jEdit/trunk/org/gjt/sp/jedit/buffer/KillRing.java 2008-08-12 18:31:39 UTC (rev 13283) @@ -51,15 +51,15 @@ { int newSize = Math.max(1, historySize); if(ring == null) - ring = new UndoManager.Remove[newSize]; + ring = new UndoManager.RemovedContent[newSize]; else if(newSize != ring.length) { - UndoManager.Remove[] newRing = new UndoManager.Remove[ + UndoManager.RemovedContent[] newRing = new UndoManager.RemovedContent[ newSize]; int newCount = Math.min(getSize(),newSize); for(int i = 0; i < newCount; i++) { - newRing[i] = (UndoManager.Remove)getElementAt(i); + newRing[i] = (UndoManager.RemovedContent)getElementAt(i); } ring = newRing; count = newCount; @@ -94,20 +94,20 @@ */ protected void reset(List source) { - UndoManager.Remove[] newRing - = new UndoManager.Remove[source.size()]; + UndoManager.RemovedContent[] newRing + = new UndoManager.RemovedContent[source.size()]; int i = 0; for(Object x: source) { - UndoManager.Remove element; + UndoManager.RemovedContent element; if(x instanceof String) { - element = new UndoManager.Remove( - null,0,0,(String)x); + element = new UndoManager.RemovedContent( + (String)x); } else { - element = (UndoManager.Remove)x; + element = (UndoManager.RemovedContent)x; } newRing[i++] = element; } @@ -157,7 +157,7 @@ called by the 'Paste Deleted' dialog where the performance is not exactly vital */ remove(index); - add((UndoManager.Remove)value); + add((UndoManager.RemovedContent)value); } //}}} //}}} @@ -165,7 +165,7 @@ //{{{ Package-private members //{{{ changed() method - void changed(UndoManager.Remove rem) + void changed(UndoManager.RemovedContent rem) { if(rem.inKillRing) { @@ -194,7 +194,7 @@ } //}}} //{{{ add() method - void add(UndoManager.Remove rem) + void add(UndoManager.RemovedContent rem) { // compare existing entries' hashcode with this int length = (wrap ? ring.length : count); @@ -244,7 +244,7 @@ { if(wrap) { - UndoManager.Remove[] newRing = new UndoManager.Remove[ + UndoManager.RemovedContent[] newRing = new UndoManager.RemovedContent[ ring.length]; int newCount = 0; for(int j = 0; j < ring.length; j++) @@ -273,7 +273,7 @@ //}}} //{{{ Private members - private UndoManager.Remove[] ring; + private UndoManager.RemovedContent[] ring; private int count; private boolean wrap; private static KillRing killRing = new KillRing(); Modified: jEdit/trunk/org/gjt/sp/jedit/buffer/UndoManager.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/buffer/UndoManager.java 2008-08-12 18:30:14 UTC (rev 13282) +++ jEdit/trunk/org/gjt/sp/jedit/buffer/UndoManager.java 2008-08-12 18:31:39 UTC (rev 13283) @@ -188,19 +188,19 @@ Remove rem = (Remove)toMerge; if(rem.offset == offset) { - rem.str = rem.str.concat(text); - rem.hashcode = rem.str.hashCode(); + rem.content.str = rem.content.str.concat(text); + rem.content.hashcode = rem.content.str.hashCode(); rem.length += length; - KillRing.getInstance().changed(rem); + KillRing.getInstance().changed(rem.content); return; } else if(offset + length == rem.offset) { - rem.str = text.concat(rem.str); - rem.hashcode = rem.str.hashCode(); + rem.content.str = text.concat(rem.content.str); + rem.content.hashcode = rem.content.str.hashCode(); rem.length += length; rem.offset = offset; - KillRing.getInstance().changed(rem); + KillRing.getInstance().changed(rem.content); return; } } @@ -217,7 +217,7 @@ else addEdit(rem); - KillRing.getInstance().add(rem); + KillRing.getInstance().add(rem.content); } //}}} //{{{ resetClearDirty method @@ -350,8 +350,28 @@ String str; } //}}} + //{{{ RemovedContent clas + // This class is held in KillRing. + public static class RemovedContent + { + String str; + int hashcode; + boolean inKillRing; + + public RemovedContent(String str) + { + this.str = str; + this.hashcode = str.hashCode(); + } + + public String toString() + { + return str; + } + }// }}} + //{{{ Remove class - public static class Remove extends Edit + static class Remove extends Edit { //{{{ Remove constructor Remove(UndoManager mgr, int offset, int length, String str) @@ -359,14 +379,13 @@ this.mgr = mgr; this.offset = offset; this.length = length; - this.str = str; - hashcode = str.hashCode(); + this.content = new RemovedContent(str); } //}}} //{{{ undo() method int undo() { - mgr.buffer.insert(offset,str); + mgr.buffer.insert(offset,content.str); if(mgr.undoClearDirty == this) mgr.buffer.setDirty(false); return offset + length; @@ -381,18 +400,10 @@ return offset; } //}}} - //{{{ toString() method - public String toString() - { - return str; - } //}}} - UndoManager mgr; int offset; int length; - String str; - int hashcode; - boolean inKillRing; + final RemovedContent content; } //}}} //{{{ CompoundEdit class This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |