Skip to content

Commit

Permalink
use getBytes() instead of looping over getByte()
Browse files Browse the repository at this point in the history
  • Loading branch information
fkaelberer committed Jun 27, 2014
1 parent 9a41659 commit fc73e2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 3 additions & 7 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals assert, calculateMD5, Catalog, Dict, error, info, isArray,
isArrayBuffer, isName, isStream, isString, createPromiseCapability,
/* globals assert, bytesToString, calculateMD5, Catalog, Dict, error, info,
isArray, isArrayBuffer, isName, isStream, isString,
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer,
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef,
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
Expand Down Expand Up @@ -301,14 +301,10 @@ var PDFDocument = (function PDFDocumentClosure() {
function find(stream, needle, limit, backwards) {
var pos = stream.pos;
var end = stream.end;
var strBuf = [];
if (pos + limit > end) {
limit = end - pos;
}
for (var n = 0; n < limit; ++n) {
strBuf.push(String.fromCharCode(stream.getByte()));
}
var str = strBuf.join('');
var str = bytesToString(stream.getBytes(limit));
stream.pos = pos;
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
if (index == -1) {
Expand Down
10 changes: 4 additions & 6 deletions src/core/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,10 @@ var FlateStream = (function FlateStreamClosure() {
this.eof = true;
}
} else {
for (var n = bufferLength; n < end; ++n) {
if ((b = str.getByte()) === -1) {
this.eof = true;
break;
}
buffer[n] = b;
var block = str.getBytes(blockLen);
buffer.set(block, bufferLength);
if (block.length < blockLen) {
this.eof = true;
}
}
return;
Expand Down

0 comments on commit fc73e2e

Please sign in to comment.