Browse Source

use getBytes() instead of looping over getByte()

fkaelberer 11 years ago
parent
commit
fc73e2e173
  1. 10
      src/core/core.js
  2. 10
      src/core/stream.js

10
src/core/core.js

@ -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) {

10
src/core/stream.js

@ -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;

Loading…
Cancel
Save