Use an object pool for stack nodes, to reduce allocations

Also, fix some leaks in the case where memory allocation failed during parsing
This commit is contained in:
Max Brunsfeld 2016-02-04 11:15:46 -08:00
parent a302ee822a
commit c96c4a08e6
8 changed files with 196 additions and 103 deletions

View file

@ -28,6 +28,9 @@ int ts_string_input_seek(void *payload, size_t character, size_t byte) {
TSInput ts_string_input_make(const char *string) {
TSStringInput *input = ts_malloc(sizeof(TSStringInput));
if (!input)
goto error;
input->string = string;
input->position = 0;
input->length = strlen(string);
@ -36,4 +39,7 @@ TSInput ts_string_input_make(const char *string) {
.read_fn = ts_string_input_read,
.seek_fn = ts_string_input_seek,
};
error:
return (TSInput){NULL, NULL, NULL};
}