Merge pull request #5005 from fkaelberer/faster_ChunkedStream_getByte

Faster chunkedStream_getByte()
This commit is contained in:
Jonas Jenwald 2014-07-18 18:23:49 +02:00
commit 9c6316fc15
3 changed files with 16 additions and 15 deletions

View File

@ -155,8 +155,15 @@ var ChunkedStream = (function ChunkedStreamClosure() {
if (pos >= this.end) { if (pos >= this.end) {
return -1; return -1;
} }
this.ensureByte(pos); var byte = this.bytes[pos];
return this.bytes[this.pos++]; if (byte === 0) {
// |byte| might be zero, because the corresponding chunk has not been
// loaded yet. In this case, this.ensureByte(pos) will throw an
// exception and nothing is returned.
this.ensureByte(pos);
}
this.pos++;
return byte;
}, },
getUint16: function ChunkedStream_getUint16() { getUint16: function ChunkedStream_getUint16() {

View File

@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals assert, calculateMD5, Catalog, Dict, error, info, isArray, /* globals assert, bytesToString, calculateMD5, Catalog, Dict, error, info,
isArrayBuffer, isName, isStream, isString, createPromiseCapability, isArray, isArrayBuffer, isName, isStream, isString,
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer, Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer,
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef, StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef,
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
@ -301,14 +301,10 @@ var PDFDocument = (function PDFDocumentClosure() {
function find(stream, needle, limit, backwards) { function find(stream, needle, limit, backwards) {
var pos = stream.pos; var pos = stream.pos;
var end = stream.end; var end = stream.end;
var strBuf = [];
if (pos + limit > end) { if (pos + limit > end) {
limit = end - pos; limit = end - pos;
} }
for (var n = 0; n < limit; ++n) { var str = bytesToString(stream.getBytes(limit));
strBuf.push(String.fromCharCode(stream.getByte()));
}
var str = strBuf.join('');
stream.pos = pos; stream.pos = pos;
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle); var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
if (index == -1) { if (index == -1) {

View File

@ -531,12 +531,10 @@ var FlateStream = (function FlateStreamClosure() {
this.eof = true; this.eof = true;
} }
} else { } else {
for (var n = bufferLength; n < end; ++n) { var block = str.getBytes(blockLen);
if ((b = str.getByte()) === -1) { buffer.set(block, bufferLength);
this.eof = true; if (block.length < blockLen) {
break; this.eof = true;
}
buffer[n] = b;
} }
} }
return; return;