Skip to content

Commit

Permalink
fix crash by OOM, when search opened in editor (fix microsoft#135950)…
Browse files Browse the repository at this point in the history
… - additional memory optimization [220Mb -> 15Mb] [1.6sec -> 2.2sec]

Slightly slower due to gc calls

usecase from microsoft#133348 (comment)
file for search - `plugins.pkgd.min.js` from https://github.com/froala/wysiwyg-editor
  • Loading branch information
Gvozd committed Nov 6, 2021
1 parent bb4a15d commit 52b56d6
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const matchToSearchResultFormat = (match: Match, longestLineNumber: number): { l
const prefix = ` ${paddingStr}${lineNumber}: `;
const prefixOffset = prefix.length;

const line = (prefix + sourceLine).replace(/\r?\n?$/, '');
// split instead of replace to avoid creating a new string object
const line = prefix + sourceLine.split(/\r?\n?$/, 1)[0];

const rangeOnThisLine = ({ start, end }: { start?: number; end?: number; }) => new Range(1, (start ?? 1) + prefixOffset, 1, (end ?? sourceLine.length + 1) + prefixOffset);

Expand Down

0 comments on commit 52b56d6

Please sign in to comment.