# HG changeset patch # User Artem Tikhomirov # Date 1296785355 -3600 # Node ID ed2b4adac51cfbf6a49b6625c4fa3dc1c2b65632 # Parent 68ba22a2133a2a7252e93a46506ad4f0e0f93f54 Index and start of the copy are distinct diff -r 68ba22a2133a -r ed2b4adac51c src/org/tmatesoft/hg/internal/KeywordFilter.java --- a/src/org/tmatesoft/hg/internal/KeywordFilter.java Fri Feb 04 02:44:32 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/KeywordFilter.java Fri Feb 04 03:09:15 2011 +0100 @@ -85,6 +85,7 @@ ByteBuffer rv = null; int keywordStart = -1; int x = src.position(); + int copyFrom = x; // needs to be updated each time we copy a slice, but not each time we modify source index (x) while (x < src.limit()) { if (keywordStart == -1) { int i = indexOf(src, '$', x, false); @@ -92,7 +93,7 @@ if (rv == null) { return src; } else { - copySlice(src, x, src.limit(), rv); + copySlice(src, copyFrom, src.limit(), rv); rv.flip(); src.position(src.limit()); return rv; @@ -117,7 +118,7 @@ rv = ByteBuffer.allocate(keywordStart - x); } // copy all from source till latest possible kw start - copySlice(src, x, keywordStart, rv); + copySlice(src, copyFrom, keywordStart, rv); rv.flip(); // and tell caller we've consumed only to the potential kw start src.position(keywordStart); @@ -132,7 +133,7 @@ // Factor of 4 is pure guess and a HACK, need to be fixed with re-expanding buffer on demand rv = ByteBuffer.allocate(isExpanding ? src.remaining() * 4 : src.remaining()); } - copySlice(src, x, keywordStart+1, rv); + copySlice(src, copyFrom, keywordStart+1, rv); rv.put(keyword.getBytes()); if (isExpanding) { rv.put((byte) ':'); @@ -143,11 +144,13 @@ rv.put((byte) '$'); keywordStart = -1; x = i+1; + copyFrom = x; continue; } else { if (rv != null) { // we've already did some substitution, thus need to copy bytes we've scanned. copySlice(src, x, i, rv); + copyFrom = i; } // no else in attempt to avoid rv creation if no real kw would be found keywordStart = i; x = i; // '$' at i wasn't consumed, hence x points to i, not i+1. This is to avoid problems with case: "sdfsd $ asdfs $Id$ sdf" @@ -158,6 +161,7 @@ // line break if (rv != null) { copySlice(src, x, i+1, rv); + copyFrom = i+1; } x = i+1; keywordStart = -1; // Wasn't keyword, really