use getBytes() instead of looping over getByte()

This commit is contained in:
fkaelberer 2014-06-27 09:09:54 +02:00
parent 9a41659ae7
commit fc73e2e173
2 changed files with 7 additions and 13 deletions

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

@ -539,12 +539,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;