Skip to content
This repository

Check maxLineLen before trying to find matching bracket #1408

Closed
wants to merge 1 commit into from

2 participants

Randy Edmunds Marijn Haverbeke
Randy Edmunds

Match Brackets code tries to find matching bracket and then checks to see if line is too long. On a minified library such as less-1.3.0.min.js (47KB) this takes ~87 sec on MacBook Pro running MacOS 10.8. And there are much larger libraries out there!

It's much faster to check the line length first. This won't fix case where code has mixed long/short lines, but that does not seem to be common.

This is to fix Brackets issue 2991 and a few others.

Not sure if this is the best fix, but it should highlight the problem and get you close :)

Randy Edmunds redmunds referenced this pull request in adobe/brackets March 29, 2013
Closed

Pasting minified file as single line #2991

Randy Edmunds redmunds referenced this pull request in adobe/brackets March 29, 2013
Closed

Performance problems with very long lines #2856

Marijn Haverbeke marijnh closed this pull request from a commit April 02, 2013
Marijn Haverbeke [matchbrackets addon] Don't fetch tokens on long lines
Without a bunch of more involved code, it has quadratic complexity, which
gets slow rather fast.

Closes #1408
bcade67
Marijn Haverbeke marijnh closed this in bcade67 April 02, 2013
Marijn Haverbeke
Owner

The current test is there because setting a mark on a long line is very slow. Scanning through it isn't necessarily slow, but the way matchbrackets does it was causing problems. See attached patches. They largely fix the slowness and make it configurable which line length is skipped.

Randy Edmunds

Verified that this fixes Brackets issues. Thanks.

Randy Edmunds redmunds deleted the branch April 07, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 29, 2013
Randy Edmunds check maxLineLen before trying to find match 808433d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 1 addition and 0 deletions. Show diff stats Hide diff stats

  1. 1  addon/edit/matchbrackets.js
1  addon/edit/matchbrackets.js
@@ -9,6 +9,7 @@
9 9
   var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
10 10
   function findMatchingBracket(cm) {
11 11
     var cur = cm.getCursor(), line = cm.getLineHandle(cur.line), pos = cur.ch - 1;
  12
+    if (cm.getLine(cur.line).length > maxLineLen) return null;
12 13
     var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
13 14
     if (!match) return null;
14 15
     var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.