Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use String.prototype.repeat() in a couple of spots #14733

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,7 @@ class Catalog {
const character = String.fromCharCode(
baseCharCode + (letterIndex % LIMIT)
);
const charBuf = [];
for (let j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
charBuf.push(character);
}
currentLabel = charBuf.join("");
currentLabel = character.repeat(Math.floor(letterIndex / LIMIT) + 1);
break;
default:
if (style) {
Expand Down
5 changes: 2 additions & 3 deletions test/unit/evaluator_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,9 @@ describe("evaluator", function () {
"(bug 1443140)",
async function () {
const NUM_INVALID_OPS = 25;
const tempArr = new Array(NUM_INVALID_OPS + 1);

// Non-path operators, should be ignored.
const invalidMoveText = tempArr.join("10 Td\n");
const invalidMoveText = "10 Td\n".repeat(NUM_INVALID_OPS);
const moveTextStream = new StringStream(invalidMoveText);
const result = await runOperatorListCheck(
partialEvaluator,
Expand All @@ -275,7 +274,7 @@ describe("evaluator", function () {
expect(result.fnArray).toEqual([]);

// Path operators, should throw error.
const invalidLineTo = tempArr.join("20 l\n");
const invalidLineTo = "20 l\n".repeat(NUM_INVALID_OPS);
const lineToStream = new StringStream(invalidLineTo);

try {
Expand Down
5 changes: 2 additions & 3 deletions test/unit/util_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ describe("util", function () {
bytes[i] = "a".charCodeAt(0);
}

// Create a string with `length` 'a' characters. We need an array of size
// `length + 1` since `join` puts the argument between the array elements.
const string = Array(length + 1).join("a");
// Create a string with `length` 'a' characters.
const string = "a".repeat(length);

expect(bytesToString(bytes)).toEqual(string);
});
Expand Down