Fixed performance issue in has_parens()
This commit is contained in:
parent
81603ecd15
commit
7f4464d8d3
|
|
@ -109,6 +109,7 @@ function OutputStream(options) {
|
||||||
var current_line = 1;
|
var current_line = 1;
|
||||||
var current_pos = 0;
|
var current_pos = 0;
|
||||||
var OUTPUT = "";
|
var OUTPUT = "";
|
||||||
|
var LAST_OUTPUT_FRAGMENT = "";
|
||||||
|
|
||||||
var to_utf8 = options.ascii_only ? function(str, identifier) {
|
var to_utf8 = options.ascii_only ? function(str, identifier) {
|
||||||
return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
|
return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
|
||||||
|
|
@ -233,7 +234,7 @@ function OutputStream(options) {
|
||||||
if (current_col > options.max_line_len) {
|
if (current_col > options.max_line_len) {
|
||||||
if (might_add_newline) {
|
if (might_add_newline) {
|
||||||
var left = OUTPUT.slice(0, might_add_newline);
|
var left = OUTPUT.slice(0, might_add_newline);
|
||||||
var right = OUTPUT.slice(might_add_newline);
|
var right = LAST_OUTPUT_FRAGMENT = OUTPUT.slice(might_add_newline);
|
||||||
if (mappings) {
|
if (mappings) {
|
||||||
var delta = right.length - current_col;
|
var delta = right.length - current_col;
|
||||||
mappings.forEach(function(mapping) {
|
mappings.forEach(function(mapping) {
|
||||||
|
|
@ -339,7 +340,7 @@ function OutputStream(options) {
|
||||||
if (!might_add_newline) do_add_mapping();
|
if (!might_add_newline) do_add_mapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT += str;
|
OUTPUT += LAST_OUTPUT_FRAGMENT = str;
|
||||||
current_pos += str.length;
|
current_pos += str.length;
|
||||||
var a = str.split(/\r?\n/), n = a.length - 1;
|
var a = str.split(/\r?\n/), n = a.length - 1;
|
||||||
current_line += n;
|
current_line += n;
|
||||||
|
|
@ -375,7 +376,7 @@ function OutputStream(options) {
|
||||||
var newline = options.beautify ? function() {
|
var newline = options.beautify ? function() {
|
||||||
if (newline_insert < 0) return print("\n");
|
if (newline_insert < 0) return print("\n");
|
||||||
if (OUTPUT[newline_insert] != "\n") {
|
if (OUTPUT[newline_insert] != "\n") {
|
||||||
OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
|
OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + (LAST_OUTPUT_FRAGMENT = OUTPUT.slice(newline_insert));
|
||||||
current_pos++;
|
current_pos++;
|
||||||
current_line++;
|
current_line++;
|
||||||
}
|
}
|
||||||
|
|
@ -576,7 +577,7 @@ function OutputStream(options) {
|
||||||
indentation : function() { return indentation },
|
indentation : function() { return indentation },
|
||||||
current_width : function() { return current_col - indentation },
|
current_width : function() { return current_col - indentation },
|
||||||
should_break : function() { return options.width && this.current_width() >= options.width },
|
should_break : function() { return options.width && this.current_width() >= options.width },
|
||||||
has_parens : function() { return OUTPUT[OUTPUT.length - 1] == "(" },
|
has_parens : function() { return LAST_OUTPUT_FRAGMENT[LAST_OUTPUT_FRAGMENT.length - 1] == "(" },
|
||||||
newline : newline,
|
newline : newline,
|
||||||
print : print,
|
print : print,
|
||||||
space : space,
|
space : space,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user