small perf fix chaching the eol string instead of switching all the time
This commit is contained in:
parent
aa93473702
commit
7c0e4747ed
|
@ -92,6 +92,18 @@ struct TokenFormatter(OutputRange)
|
||||||
this.output = output;
|
this.output = output;
|
||||||
this.astInformation = astInformation;
|
this.astInformation = astInformation;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
|
{
|
||||||
|
auto eol = config.end_of_line;
|
||||||
|
if (eol == eol.cr)
|
||||||
|
this.eolString = "\r";
|
||||||
|
else if (eol == eol.lf)
|
||||||
|
this.eolString = "\n";
|
||||||
|
else if (eol == eol.crlf)
|
||||||
|
this.eolString = "\r\n";
|
||||||
|
else if (eol == eol.unspecified)
|
||||||
|
assert(false, "config.end_of_line was unspecified");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the formatting process
|
/// Runs the formatting process
|
||||||
|
@ -136,6 +148,9 @@ private:
|
||||||
/// Configuration
|
/// Configuration
|
||||||
const Config* config;
|
const Config* config;
|
||||||
|
|
||||||
|
/// chached end of line string
|
||||||
|
const string eolString;
|
||||||
|
|
||||||
/// Keep track of whether or not an extra newline was just added because of
|
/// Keep track of whether or not an extra newline was just added because of
|
||||||
/// an import statement.
|
/// an import statement.
|
||||||
bool justAddedExtraNewline;
|
bool justAddedExtraNewline;
|
||||||
|
@ -1247,20 +1262,7 @@ private:
|
||||||
{
|
{
|
||||||
import dfmt.editorconfig : EOL;
|
import dfmt.editorconfig : EOL;
|
||||||
|
|
||||||
final switch (config.end_of_line)
|
output.put(eolString);
|
||||||
{
|
|
||||||
case EOL.cr:
|
|
||||||
output.put("\r");
|
|
||||||
break;
|
|
||||||
case EOL.lf:
|
|
||||||
output.put("\n");
|
|
||||||
break;
|
|
||||||
case EOL.crlf:
|
|
||||||
output.put("\r\n");
|
|
||||||
break;
|
|
||||||
case EOL.unspecified:
|
|
||||||
assert(false, "config.end_of_line was unspecified");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void newline()
|
void newline()
|
||||||
|
|
Loading…
Reference in New Issue