You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by lm...@apache.org on 2001/07/20 19:26:48 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/utils StringPool.java
lmartin 01/07/20 10:26:48
Modified: java/src/org/apache/xerces/utils StringPool.java
Log:
Performance patches related to array resizing - submitted by Henry Zongaro
Revision Changes Path
1.8 +22 -28 xml-xerces/java/src/org/apache/xerces/utils/StringPool.java
Index: StringPool.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/utils/StringPool.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- StringPool.java 2000/07/21 03:42:44 1.7
+++ StringPool.java 2001/07/20 17:26:48 1.8
@@ -164,11 +164,9 @@
//
// String interfaces
//
- private boolean ensureCapacity(int chunk, int index) {
- try {
- return fOffset[chunk][index] == 0;
- } catch (ArrayIndexOutOfBoundsException ex) {
- if (index == 0) {
+ private void ensureCapacity(int chunk, int index) {
+
+ if (chunk >= fOffset.length) {
String[][] newString = new String[chunk * 2][];
System.arraycopy(fString, 0, newString, 0, chunk);
fString = newString;
@@ -184,7 +182,9 @@
newInt = new int[chunk * 2][];
System.arraycopy(fCharsOffset, 0, newInt, 0, chunk);
fCharsOffset = newInt;
- } else {
+ } else if (fOffset[chunk] == null) {
+ }
+ else if (index >= fOffset[chunk].length) {
String[] newString = new String[index * 2];
System.arraycopy(fString[chunk], 0, newString, 0, index);
fString[chunk] = newString;
@@ -200,16 +200,16 @@
newInt = new int[index * 2];
System.arraycopy(fCharsOffset[chunk], 0, newInt, 0, index);
fCharsOffset[chunk] = newInt;
- return true;
- }
- } catch (NullPointerException ex) {
+ return;
+ } else {
+ return;
}
fString[chunk] = new String[INITIAL_CHUNK_SIZE];
fStringProducer[chunk] = new StringPool.StringProducer[INITIAL_CHUNK_SIZE];
fOffset[chunk] = new int[INITIAL_CHUNK_SIZE];
fLength[chunk] = new int[INITIAL_CHUNK_SIZE];
fCharsOffset[chunk] = new int[INITIAL_CHUNK_SIZE];
- return true;
+ return;
}
public int addString(String str) {
int chunk;
@@ -272,7 +272,6 @@
fShuffleCount = 0;
}
public void updateCacheLine(int symbolIndex, int totalMisses, int length) {
-//System.err.println("found symbol " + toString(symbolIndex) + " after " + totalMisses + " total misses (" + (totalMisses/length) + " misses per character).");
if (++fShuffleCount > 200) {
// if (fShuffleCount == 201) System.out.println("Stopped shuffling...");
return;
@@ -540,24 +539,19 @@
//
// String list support
//
- private boolean ensureListCapacity(int chunk, int index) {
- try {
- return fStringList[chunk][index] == 0;
- } catch (ArrayIndexOutOfBoundsException ex) {
- if (index == 0) {
- int[][] newInt = new int[chunk * 2][];
- System.arraycopy(fStringList, 0, newInt, 0, chunk);
- fStringList = newInt;
- } else {
- int[] newInt = new int[index * 2];
- System.arraycopy(fStringList[chunk], 0, newInt, 0, index);
- fStringList[chunk] = newInt;
- return true;
- }
- } catch (NullPointerException ex) {
+ private void ensureListCapacity(int chunk, int index) {
+ if (chunk >= fStringList.length) {
+ int[][] newInt = new int[chunk * 2][];
+ System.arraycopy(fStringList, 0, newInt, 0, chunk);
+ fStringList = newInt;
+ fStringList[chunk] = new int[INITIAL_CHUNK_SIZE];
+ } else if (fStringList[chunk] == null) {
+ fStringList[chunk] = new int[INITIAL_CHUNK_SIZE];
+ } else if (index >= fStringList[chunk].length) {
+ int[] newInt = new int[index * 2];
+ System.arraycopy(fStringList[chunk], 0, newInt, 0, index);
+ fStringList[chunk] = newInt;
}
- fStringList[chunk] = new int[INITIAL_CHUNK_SIZE];
- return true;
}
public int startStringList() {
fActiveStringList = fStringListCount;
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org