Skip to content

Commit c62a193

Browse files
Merge pull request #9072 from Snuffleupagus/more-stringToBytes
Use `stringToBytes` in more places
2 parents ad74f6e + 5e62781 commit c62a193

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/core/stream.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
import {
17-
createObjectURL, FormatError, isSpace, shadow, Util
17+
createObjectURL, FormatError, isSpace, shadow, stringToBytes, Util
1818
} from '../shared/util';
1919
import { isDict } from './primitives';
2020
import { JpegImage } from './jpg';
@@ -109,11 +109,7 @@ var Stream = (function StreamClosure() {
109109

110110
var StringStream = (function StringStreamClosure() {
111111
function StringStream(str) {
112-
var length = str.length;
113-
var bytes = new Uint8Array(length);
114-
for (var n = 0; n < length; ++n) {
115-
bytes[n] = str.charCodeAt(n);
116-
}
112+
let bytes = stringToBytes(str);
117113
Stream.call(this, bytes);
118114
}
119115

src/display/network.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { assert, createPromiseCapability } from '../shared/util';
16+
import { assert, createPromiseCapability, stringToBytes } from '../shared/util';
1717
import {
1818
createResponseStatusError, validateRangeRequestCapabilities
1919
} from './network_utils';
@@ -48,11 +48,7 @@ function getArrayBuffer(xhr) {
4848
if (typeof data !== 'string') {
4949
return data;
5050
}
51-
var length = data.length;
52-
var array = new Uint8Array(length);
53-
for (var i = 0; i < length; i++) {
54-
array[i] = data.charCodeAt(i) & 0xFF;
55-
}
51+
let array = stringToBytes(data);
5652
return array.buffer;
5753
}
5854

0 commit comments

Comments
 (0)