The parser spends the majority of its time allocating and freeing trees and stack nodes. Also, the memory footprint of the AST is a significant concern when using tree-sitter with large files. This library is already unlikely to work very well with source files larger than 4GB, so representing rows, columns, byte lengths and child indices as unsigned 32 bit integers seems like the right choice.
39 lines
901 B
C++
39 lines
901 B
C++
#ifndef HELPERS_SPY_INPUT_H_
|
|
#define HELPERS_SPY_INPUT_H_
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include "tree_sitter/runtime.h"
|
|
|
|
struct SpyInputEdit {
|
|
size_t start_byte;
|
|
size_t bytes_removed;
|
|
std::string text_inserted;
|
|
};
|
|
|
|
class SpyInput {
|
|
uint32_t chars_per_chunk;
|
|
uint32_t buffer_size;
|
|
char *buffer;
|
|
uint32_t byte_offset;
|
|
std::vector<SpyInputEdit> undo_stack;
|
|
|
|
static const char * read(void *, uint32_t *);
|
|
static int seek(void *, uint32_t, uint32_t);
|
|
std::pair<std::string, TSPoint> swap_substr(size_t, size_t, std::string);
|
|
|
|
public:
|
|
SpyInput(std::string content, size_t chars_per_chunk);
|
|
~SpyInput();
|
|
|
|
TSInput input();
|
|
void clear();
|
|
TSInputEdit replace(size_t start_char, size_t chars_removed, std::string text);
|
|
TSInputEdit undo();
|
|
|
|
std::string content;
|
|
TSInputEncoding encoding;
|
|
std::vector<std::string> strings_read;
|
|
};
|
|
|
|
#endif // HELPERS_SPY_INPUT_H_
|