diff options
author | Alexandre Montplaisir | 2013-07-19 19:50:58 +0000 |
---|---|---|
committer | Alexandre Montplaisir | 2013-07-20 16:43:58 +0000 |
commit | b1046ecac5b3d69c010e7d9977b268c83f101848 (patch) | |
tree | 6c89e2f7a057ba5896cebd74349e56bbc00805dd | |
parent | 04582fe2761c3563fb3b33414fd6849ab22df44d (diff) | |
download | org.eclipse.linuxtools-b1046ecac5b3d69c010e7d9977b268c83f101848.tar.gz org.eclipse.linuxtools-b1046ecac5b3d69c010e7d9977b268c83f101848.tar.xz org.eclipse.linuxtools-b1046ecac5b3d69c010e7d9977b268c83f101848.zip |
tmf: Avoid a string copy when reading state intervals
HTInterval's constructor calls computeStringsEntrySize(), which
does a string copy (getBytes()) to get the real size of the string.
When reading an interval from disk, we already have this size since
it's written in the file, so we can avoid this extra copy.
Change-Id: I9f70c861ec3e94b00c9060825933826d2244bb59
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/14715
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
-rw-r--r-- | lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java index 886640ea1e..7e942d658e 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java @@ -38,6 +38,11 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> { private static final byte TYPE_STRING = 1; private static final byte TYPE_LONG = 2; + /* String entry sizes of different state values */ + private static final int NO_ENTRY_SIZE = 0; + private static final int LONG_ENTRY_SIZE = 8; + // sizes of string values depend on the string itself + private final long start; private final long end; private final int attribute; @@ -71,6 +76,32 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> { } /** + * "Faster" constructor for inner use only. When we build an interval when + * reading it from disk (with {@link #readFrom}), we already know the size + * of the strings entry, so there is no need to call + * {@link #computeStringsEntrySize()} and do an extra copy. + * + * @param intervalStart + * @param intervalEnd + * @param attribute + * @param value + * @param size + * @throws TimeRangeException + */ + private HTInterval(long intervalStart, long intervalEnd, int attribute, + TmfStateValue value, int size) throws TimeRangeException { + if (intervalStart > intervalEnd) { + throw new TimeRangeException(); + } + + this.start = intervalStart; + this.end = intervalEnd; + this.attribute = attribute; + this.sv = value; + this.stringsEntrySize = size; + } + + /** * Reader constructor. Builds the interval using an already-allocated * ByteBuffer, which normally comes from a NIO FileChannel. * @@ -99,11 +130,13 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> { case TYPE_NULL: value = TmfStateValue.nullValue(); + valueSize = NO_ENTRY_SIZE; break; case TYPE_INTEGER: /* "ValueOrOffset" is the straight value */ value = TmfStateValue.newValueInt(valueOrOffset); + valueSize = NO_ENTRY_SIZE; break; case TYPE_STRING: @@ -142,6 +175,7 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> { buffer.mark(); buffer.position(valueOrOffset); value = TmfStateValue.newValueLong(buffer.getLong()); + valueSize = LONG_ENTRY_SIZE; /* * Restore the file pointer's position (so we can read the next @@ -155,7 +189,7 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> { } try { - interval = new HTInterval(intervalStart, intervalEnd, attribute, value); + interval = new HTInterval(intervalStart, intervalEnd, attribute, value, valueSize); } catch (TimeRangeException e) { throw new IOException(errMsg); } @@ -304,10 +338,10 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> { case NULL: case INTEGER: /* Those don't use the strings section at all */ - return 0; + return NO_ENTRY_SIZE; case LONG: /* The value's bytes are written directly into the strings section */ - return 8; + return LONG_ENTRY_SIZE; case STRING: try { /* String's length + 2 (1 byte for size, 1 byte for \0 at the end */ |