mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Changeset: Use string concatenation instead of array join
People report that string concatenation is faster. Also, I think it's more readable.
This commit is contained in:
parent
097f2623c6
commit
0ae8fb1441
1 changed files with 12 additions and 22 deletions
|
@ -482,24 +482,22 @@ exports.mergingOpAssembler = () => {
|
||||||
* @returns {OpAssembler}
|
* @returns {OpAssembler}
|
||||||
*/
|
*/
|
||||||
exports.opAssembler = () => {
|
exports.opAssembler = () => {
|
||||||
const pieces = [];
|
let serialized = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Op} op - Operation to add. Ownership remains with the caller.
|
* @param {Op} op - Operation to add. Ownership remains with the caller.
|
||||||
*/
|
*/
|
||||||
const append = (op) => {
|
const append = (op) => {
|
||||||
pieces.push(op.attribs);
|
if (op.attribs != null) serialized += op.attribs;
|
||||||
if (op.lines) {
|
if (op.lines) serialized += `|${exports.numToString(op.lines)}`;
|
||||||
pieces.push('|', exports.numToString(op.lines));
|
if (op.opcode != null) serialized += op.opcode;
|
||||||
}
|
serialized += exports.numToString(op.chars);
|
||||||
pieces.push(op.opcode);
|
|
||||||
pieces.push(exports.numToString(op.chars));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const toString = () => pieces.join('');
|
const toString = () => serialized;
|
||||||
|
|
||||||
const clear = () => {
|
const clear = () => {
|
||||||
pieces.length = 0;
|
serialized = '';
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
append,
|
append,
|
||||||
|
@ -573,22 +571,14 @@ exports.stringIterator = (str) => {
|
||||||
/**
|
/**
|
||||||
* @returns {StringAssembler}
|
* @returns {StringAssembler}
|
||||||
*/
|
*/
|
||||||
exports.stringAssembler = () => {
|
exports.stringAssembler = () => ({
|
||||||
const pieces = [];
|
_str: '',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} x -
|
* @param {string} x -
|
||||||
*/
|
*/
|
||||||
const append = (x) => {
|
append(x) { this._str += String(x); },
|
||||||
pieces.push(String(x));
|
toString() { return this._str; },
|
||||||
};
|
});
|
||||||
|
|
||||||
const toString = () => pieces.join('');
|
|
||||||
return {
|
|
||||||
append,
|
|
||||||
toString,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} StringArrayLike
|
* @typedef {object} StringArrayLike
|
||||||
|
|
Loading…
Reference in a new issue