You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2020/12/30 17:03:27 UTC
svn commit: r1884949 -
/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
Author: centic
Date: Wed Dec 30 17:03:27 2020
New Revision: 1884949
URL: http://svn.apache.org/viewvc?rev=1884949&view=rev
Log:
Slightly re-arrange code to only perform computations if we do not exit the loop anyway
Also simplify code somewhat
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java?rev=1884949&r1=1884948&r2=1884949&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java Wed Dec 30 17:03:27 2020
@@ -241,17 +241,16 @@ public class TextPieceTable implements C
for (TextPiece textPiece : _textPiecesFCOrder) {
final int tpStart = textPiece.getPieceDescriptor()
.getFilePosition();
+ if (endBytePosExclusive <= tpStart)
+ break;
+
final int tpEnd = textPiece.getPieceDescriptor().getFilePosition()
+ textPiece.bytesLength();
if (startBytePosInclusive > tpEnd)
continue;
- if (endBytePosExclusive <= tpStart)
- break;
- final int rangeStartBytes = Math.max(tpStart,
- startBytePosInclusive);
+ final int rangeStartBytes = Math.max(tpStart, startBytePosInclusive);
final int rangeEndBytes = Math.min(tpEnd, endBytePosExclusive);
- final int rangeLengthBytes = rangeEndBytes - rangeStartBytes;
if (rangeStartBytes > rangeEndBytes)
continue;
@@ -260,6 +259,7 @@ public class TextPieceTable implements C
final int rangeStartCp = textPiece.getStart()
+ (rangeStartBytes - tpStart) / encodingMultiplier;
+ final int rangeLengthBytes = rangeEndBytes - rangeStartBytes;
final int rangeEndCp = rangeStartCp + rangeLengthBytes
/ encodingMultiplier;
@@ -290,12 +290,11 @@ public class TextPieceTable implements C
logger.log(
POILogger.WARN,
"Text piece has boundaries [",
- Integer.valueOf(textPiece.getStart()),
+ textPiece.getStart(),
"; ",
- Integer.valueOf(textPiece.getEnd()),
+ textPiece.getEnd(),
") but length ",
- Integer.valueOf(textPiece.getEnd()
- - textPiece.getStart()));
+ textPiece.getEnd() - textPiece.getStart());
}
docText.replace(textPiece.getStart(), textPiece.getStart()
@@ -303,8 +302,8 @@ public class TextPieceTable implements C
}
logger.log(POILogger.DEBUG, "Document text were rebuilded in ",
- Long.valueOf(System.currentTimeMillis() - start), " ms (",
- Integer.valueOf(docText.length()), " chars)");
+ System.currentTimeMillis() - start, " ms (",
+ docText.length(), " chars)");
return docText;
}
@@ -326,11 +325,7 @@ public class TextPieceTable implements C
continue;
}
- if (pieceStart > bytePos) {
- return false;
- }
-
- return true;
+ return pieceStart <= bytePos;
}
return false;
@@ -347,10 +342,7 @@ public class TextPieceTable implements C
int left = Math.max(startBytePos, pieceStart);
int right = Math.min(endBytePos, pieceStart + tp.bytesLength());
- if (left >= right)
- return false;
-
- return true;
+ return left < right;
}
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org