Use TRANSFER_BUFFER for did_exceed_match_limit

This bridges the gap between how the C API reports this for a query
cursor, but the wasm API defines the method on a query.  Whenever you
call a query method that might exceed the match limit, we call the C API
function and transfer the result across the wasm boundary, storing the
result in the JavaScript wrapper class.
This commit is contained in:
Douglas Creager 2021-04-28 15:46:12 -04:00
parent e8eb3c5d5a
commit b742e88108
3 changed files with 12 additions and 9 deletions

View file

@ -622,8 +622,11 @@ void ts_query_matches_wasm(
}
}
bool did_exceed_match_limit =
ts_query_cursor_did_exceed_match_limit(scratch_query_cursor);
TRANSFER_BUFFER[0] = (const void *)(match_count);
TRANSFER_BUFFER[1] = result.contents;
TRANSFER_BUFFER[2] = (const void *)(did_exceed_match_limit);
}
void ts_query_captures_wasm(
@ -667,13 +670,9 @@ void ts_query_captures_wasm(
}
}
bool did_exceed_match_limit =
ts_query_cursor_did_exceed_match_limit(scratch_query_cursor);
TRANSFER_BUFFER[0] = (const void *)(capture_count);
TRANSFER_BUFFER[1] = result.contents;
}
bool ts_query_did_exceed_match_limit_wasm(
const TSQuery *self
) {
if (!scratch_query_cursor) return false;
return ts_query_cursor_did_exceed_match_limit(scratch_query_cursor);
TRANSFER_BUFFER[2] = (const void *)(did_exceed_match_limit);
}

View file

@ -945,6 +945,7 @@ class Query {
this.setProperties = setProperties;
this.assertedProperties = assertedProperties;
this.refutedProperties = refutedProperties;
this.exceededMatchLimit = false;
}
delete() {
@ -969,7 +970,9 @@ class Query {
const rawCount = getValue(TRANSFER_BUFFER, 'i32');
const startAddress = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
const didExceedMatchLimit = getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
const result = new Array(rawCount);
this.exceededMatchLimit = !!didExceedMatchLimit;
let filteredCount = 0;
let address = startAddress;
@ -1014,7 +1017,9 @@ class Query {
const count = getValue(TRANSFER_BUFFER, 'i32');
const startAddress = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
const didExceedMatchLimit = getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
const result = [];
this.exceededMatchLimit = !!didExceedMatchLimit;
const captures = [];
let address = startAddress;
@ -1050,7 +1055,7 @@ class Query {
}
didExceedMatchLimit() {
return C._ts_query_did_exceed_match_limit_wasm(this[0]);
return this.exceededMatchLimit;
}
}

View file

@ -76,7 +76,6 @@
"_ts_query_capture_name_for_id",
"_ts_query_captures_wasm",
"_ts_query_delete",
"_ts_query_did_exceed_match_limit_wasm",
"_ts_query_matches_wasm",
"_ts_query_new",
"_ts_query_pattern_count",