Refactor c code generator

It's been rewritten in a less functional style. String copies were actually
taking significant time for large parsers.
This commit is contained in:
Max Brunsfeld 2014-06-16 21:29:04 -07:00
parent 1daaf4485f
commit c312f985c8
3 changed files with 224 additions and 189 deletions

View file

@ -23,7 +23,7 @@ namespace tree_sitter {
str_replace(&input, "\n", "\\n");
return input;
}
string escape_char(char character) {
switch (character) {
case '\0':
@ -44,26 +44,5 @@ namespace tree_sitter {
return string() + character;
}
}
string join(vector<string> lines, string separator) {
string result;
bool started = false;
for (auto line : lines) {
if (started) result += separator;
started = true;
result += line;
}
return result;
}
string join(vector<string> lines) {
return join(lines, "\n");
}
string indent(string input) {
string tab = " ";
util::str_replace(&input, "\n", "\n" + tab);
return tab + input;
}
}
}