mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
Changeset: Return a new op object by default when iterating
Reusing the same op object for each iteration can result in very weird behaviors because previously yielded op objects will get a surprise mutation. It is unclear why the code was written to reuse the same object. There was no comment, nor is there a commit message providing rationale (it has behaved this way since the very first commit). Perhaps the objects were reused to improve performance (fewer object allocations that need to be garbage collected). I do expect this change to reduce performance somewhat, but not enough to warrant reverting this commit.
This commit is contained in:
parent
718da6fc1b
commit
b9753dcc71
1 changed files with 2 additions and 3 deletions
|
@ -126,10 +126,9 @@ exports.opIterator = (opsStr, optStartIndex) => {
|
|||
return result;
|
||||
};
|
||||
let regexResult = nextRegexMatch();
|
||||
const obj = exports.newOp();
|
||||
|
||||
const next = (optObj) => {
|
||||
const op = (optObj || obj);
|
||||
const next = (optOp) => {
|
||||
const op = optOp || exports.newOp();
|
||||
if (regexResult[0]) {
|
||||
op.attribs = regexResult[1];
|
||||
op.lines = exports.parseNum(regexResult[2] || 0);
|
||||
|
|
Loading…
Reference in a new issue