Skip to content

Commit e674da4

Browse files
committed
optimize node_get_text
1 parent 4b4f1f6 commit e674da4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tree_sitter/binding/node.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,13 @@ PyObject *node_get_text(Node *self, void *Py_UNUSED(payload)) {
637637

638638
// Update current_point and current_offset
639639
Py_ssize_t bytes_read = PyBytes_Size(rv);
640+
const char *rv_str = PyBytes_AsString(rv); // Retrieve the string pointer once
640641
for (Py_ssize_t i = 0; i < bytes_read; ++i) {
641-
if (PyBytes_AsString(rv)[i] == '\n') {
642-
current_point.row += 1;
642+
if (rv_str[i] == '\n') {
643+
++current_point.row;
643644
current_point.column = 0;
644645
} else {
645-
current_point.column += 1;
646+
++current_point.column;
646647
}
647648
}
648649
current_offset += bytes_read;

0 commit comments

Comments
 (0)