You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/06/14 17:43:47 UTC
svn commit: r954521 - in /poi/trunk/src:
documentation/content/xdocs/status.xml
ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
Author: nick
Date: Mon Jun 14 15:43:47 2010
New Revision: 954521
URL: http://svn.apache.org/viewvc?rev=954521&view=rev
Log:
Fix bug #49432 - Lazy caching of XSSFComment CTComment objects by reference, to make repeated comment searching faster
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=954521&r1=954520&r2=954521&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Jun 14 15:43:47 2010
@@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta2" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">49432 - Lazy caching of XSSFComment CTComment objects by reference, to make repeated comment searching faster</action>
<action dev="POI-DEVELOPERS" type="fix">Better handling of Outlook messages in HSMF when there's no recipient email address</action>
<action dev="POI-DEVELOPERS" type="fix">When formatting numbers with DataFormatter, handle brackets following colours</action>
</release>
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java?rev=954521&r1=954520&r2=954521&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java Mon Jun 14 15:43:47 2010
@@ -19,20 +19,27 @@ package org.apache.poi.xssf.model;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
public class CommentsTable extends POIXMLDocumentPart {
private CTComments comments;
+ /**
+ * XML Beans uses a list, which is very slow
+ * to search, so we wrap things with our own
+ * map for fast lookup.
+ */
+ private Map<String, CTComment> commentRefs;
public CommentsTable() {
super();
@@ -67,6 +74,17 @@ public class CommentsTable extends POIXM
writeTo(out);
out.close();
}
+
+ /**
+ * Called after the reference is updated, so that
+ * we can reflect that in our cache
+ */
+ public void referenceUpdated(String oldReference, CTComment comment) {
+ if(commentRefs != null) {
+ commentRefs.remove(oldReference);
+ commentRefs.put(comment.getRef(), comment);
+ }
+ }
public int getNumberOfComments() {
return comments.getCommentList().sizeOfCommentArray();
@@ -95,18 +113,26 @@ public class CommentsTable extends POIXM
}
public CTComment getCTComment(String cellRef) {
- for (CTComment comment : comments.getCommentList().getCommentArray()) {
- if (cellRef.equals(comment.getRef())) {
- return comment;
- }
+ // Create the cache if needed
+ if(commentRefs == null) {
+ commentRefs = new HashMap<String, CTComment>();
+ for (CTComment comment : comments.getCommentList().getCommentList()) {
+ commentRefs.put(comment.getRef(), comment);
+ }
}
- return null;
+
+ // Return the comment, or null if not known
+ return commentRefs.get(cellRef);
}
public CTComment newComment() {
CTComment ct = comments.getCommentList().addNewComment();
ct.setRef("A1");
ct.setAuthorId(0);
+
+ if(commentRefs != null) {
+ commentRefs.put(ct.getRef(), ct);
+ }
return ct;
}
@@ -116,6 +142,10 @@ public class CommentsTable extends POIXM
CTComment comment = lst.getCommentArray(i);
if (cellRef.equals(comment.getRef())) {
lst.removeComment(i);
+
+ if(commentRefs != null) {
+ commentRefs.remove(cellRef);
+ }
return true;
}
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java?rev=954521&r1=954520&r2=954521&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java Mon Jun 14 15:43:47 2010
@@ -110,8 +110,12 @@ public class XSSFComment implements Comm
* @param col the 0-based column of the cell that contains the comment
*/
public void setColumn(int col) {
+ String oldRef = _comment.getRef();
+
CellReference ref = new CellReference(getRow(), col);
- _comment.setRef(ref.formatAsString());
+ _comment.setRef(ref.formatAsString());
+ _comments.referenceUpdated(oldRef, _comment);
+
if(_vmlShape != null) _vmlShape.getClientDataArray(0).setColumnArray(0, new BigInteger(String.valueOf(col)));
}
@@ -121,9 +125,13 @@ public class XSSFComment implements Comm
* @param row the 0-based row of the cell that contains the comment
*/
public void setRow(int row) {
+ String oldRef = _comment.getRef();
+
String newRef =
(new CellReference(row, getColumn())).formatAsString();
_comment.setRef(newRef);
+ _comments.referenceUpdated(oldRef, _comment);
+
if(_vmlShape != null) _vmlShape.getClientDataArray(0).setRowArray(0, new BigInteger(String.valueOf(row)));
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=954521&r1=954520&r2=954521&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Mon Jun 14 15:43:47 2010
@@ -175,9 +175,14 @@ public class XSSFSheet extends POIXMLDoc
initRows(worksheet);
columnHelper = new ColumnHelper(worksheet);
+ // Look for bits we're interested in
for(POIXMLDocumentPart p : getRelations()){
- if(p instanceof CommentsTable) sheetComments = (CommentsTable)p;
+ if(p instanceof CommentsTable) {
+ sheetComments = (CommentsTable)p;
+ break;
+ }
}
+
// Process external hyperlinks for the sheet, if there are any
initHyperlinks();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org