Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Use faster setText when replacing entire buffer contents
Browse files Browse the repository at this point in the history
Summary:`setText` is 3-4x faster than `setTextViaDiff`. Using it when replacing
the entire contents of the buffer makes clicking through files in the
diff-view tree show the file up to 100ms faster.

**Test run #1**

setText, 39.4ms:
{F60653266}

setTextViaDiff, 170.5ms:
{F60653267}

**Test run #2**

setText, 68.4ms:
{F60653269}

setTextViaDiff, 171.8ms:
{F60653270}

Reviewed By: mostafaeweda

Differential Revision: D3203887

fb-gh-sync-id: 7d78e07373d688654f6f6f723f30013ffe9e06fd
fbshipit-source-id: 7d78e07373d688654f6f6f723f30013ffe9e06fd
  • Loading branch information
Ross Allen authored and Facebook Github Bot 8 committed Apr 22, 2016
1 parent 361a7b8 commit 539c6d7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/nuclide-diff-view/lib/DiffViewEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@ export default class DiffViewEditor {
}

setFileContents(filePath: string, contents: string): void {
// The text is set via diffs to keep the cursor position.
const buffer = this._editor.getBuffer();
if (buffer.getText() !== contents) {
buffer.setTextViaDiff(contents);
if (buffer.getPath() === filePath && !buffer.isEmpty()) {
// The text is set via diffs to keep the cursor position when updating the file that is
// already active.
buffer.setTextViaDiff(contents);
} else {
// `setText` is faster than diffing and is used for speed when the buffer is changing to a
// different path or when an editable buffer is being loaded for the first time
// (`buffer.isEmpty() === true`) because maintaining cursor position between file changes is
// not needed.
buffer.setText(contents);
}
}
const grammar = atom.grammars.selectGrammar(filePath, contents);
this._editor.setGrammar(grammar);
Expand Down

0 comments on commit 539c6d7

Please sign in to comment.