Replace usage of ArrayIndexOutOfBoundsException in treewalk
Using exceptions during normal operations - for example with the desire of expanding an array in the failure case - can have a severe performance impact. When exceptions are instantiated, a stack trace is collected. Generating stack trace can be expensive. Compared to that, checking an array for length - even if done many times - is cheap since this is a check that can run in just a handful of CPU cycles. Change-Id: Ifaf10623f6a876c9faecfa44654c9296315adfcb Signed-off-by: Patrick Hiesel <hiesel@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
2b9dd32a82
commit
6185db3d77
|
@ -239,12 +239,10 @@ protected AbstractTreeIterator(AbstractTreeIterator p) {
|
|||
path = p.path;
|
||||
pathOffset = p.pathLen + 1;
|
||||
|
||||
try {
|
||||
path[pathOffset - 1] = '/';
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
if (pathOffset > path.length) {
|
||||
growPath(p.pathLen);
|
||||
path[pathOffset - 1] = '/';
|
||||
}
|
||||
path[pathOffset - 1] = '/';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -387,14 +387,13 @@ private void parseEntry() {
|
|||
tmp = pathOffset;
|
||||
for (;; tmp++) {
|
||||
c = raw[ptr++];
|
||||
if (c == 0)
|
||||
if (c == 0) {
|
||||
break;
|
||||
try {
|
||||
path[tmp] = c;
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
growPath(tmp);
|
||||
path[tmp] = c;
|
||||
}
|
||||
if (tmp >= path.length) {
|
||||
growPath(tmp);
|
||||
}
|
||||
path[tmp] = c;
|
||||
}
|
||||
pathLen = tmp;
|
||||
nextPtr = ptr + OBJECT_ID_LENGTH;
|
||||
|
|
Loading…
Reference in New Issue