Cram terminal subtree data into a 64-bit integer when possible

This commit is contained in:
Max Brunsfeld 2018-09-17 13:12:13 -07:00
parent e00c3bbdb9
commit b29d0f622f
21 changed files with 1258 additions and 1007 deletions

View file

@ -35,6 +35,14 @@ bool operator>(const TSPoint &left, const TSPoint &right) {
return right < left;
}
Length operator*(const Length &length, uint32_t factor) {
return {length.bytes * factor, {0, length.extent.column * factor}};
}
Length operator+(const Length &left, const Length &right) {
return length_add(left, right);
}
std::ostream &operator<<(std::ostream &stream, const TSPoint &point) {
return stream << "{" << point.row << ", " << point.column << "}";
}

View file

@ -14,6 +14,10 @@ bool operator==(const TSRange &left, const TSRange &right);
bool operator==(const Length &left, const Length &right);
Length operator*(const Length &length, uint32_t factor);
Length operator+(const Length &left, const Length &right);
std::ostream &operator<<(std::ostream &stream, const TSPoint &point);
std::ostream &operator<<(std::ostream &stream, const TSRange &range);

View file

@ -14,18 +14,18 @@ const char *symbol_names[24] = {
"twenty-two", "twenty-three"
};
SubtreeArray *tree_array(std::vector<const Subtree *> trees) {
SubtreeArray *tree_array(std::vector<Subtree> trees) {
static SubtreeArray result;
result.capacity = trees.size();
result.size = trees.size();
result.contents = (const Subtree **)calloc(trees.size(), sizeof(Subtree *));
result.contents = (Subtree *)calloc(trees.size(), sizeof(Subtree));
for (size_t i = 0; i < trees.size(); i++) {
result.contents[i] = trees[i];
}
return &result;
}
ostream &operator<<(std::ostream &stream, const Subtree *tree) {
ostream &operator<<(std::ostream &stream, Subtree tree) {
static TSLanguage DUMMY_LANGUAGE = {};
DUMMY_LANGUAGE.symbol_names = symbol_names;
char *string = ts_subtree_string(tree, &DUMMY_LANGUAGE, false);
@ -52,13 +52,10 @@ bool operator==(const TSNode &left, const TSNode &right) {
ts_node_start_point(left) == ts_node_start_point(right);
}
bool operator==(const std::vector<const Subtree *> &vec, const SubtreeArray &array) {
if (vec.size() != array.size)
return false;
for (size_t i = 0; i < array.size; i++)
if (array.contents[i] != vec[i])
return false;
return true;
bool operator==(const std::vector<Subtree> &vec, const SubtreeArray &array) {
return
vec.size() == array.size &&
std::memcmp(vec.data(), array.contents, array.size * sizeof(Subtree)) == 0;
}
void assert_consistent_tree_sizes(TSNode node) {

View file

@ -6,12 +6,12 @@
#include <string>
extern const char *symbol_names[24];
SubtreeArray *tree_array(std::vector<const Subtree *> trees);
SubtreeArray *tree_array(std::vector<Subtree> trees);
std::ostream &operator<<(std::ostream &stream, const Subtree *tree);
std::ostream &operator<<(std::ostream &stream, Subtree tree);
std::ostream &operator<<(std::ostream &stream, const TSNode &node);
bool operator==(const TSNode &left, const TSNode &right);
bool operator==(const std::vector<const Subtree *> &right, const SubtreeArray &array);
bool operator==(const std::vector<Subtree> &right, const SubtreeArray &array);
void assert_consistent_tree_sizes(TSNode node);