mirror of
https://github.com/janet-lang/janet
synced 2024-11-10 10:49:54 +00:00
refactor(c-api): Remove unneded checks due to changes to use size_t
This commit is contained in:
parent
e08e3ba46f
commit
3be71dcc0b
@ -90,8 +90,6 @@ void janet_array_ensure(JanetArray *array, size_t capacity, size_t growth) {
|
||||
|
||||
/* Set the count of an array. Extend with nil if needed. */
|
||||
void janet_array_setcount(JanetArray *array, size_t count) {
|
||||
if (count < 0)
|
||||
return;
|
||||
if (count > array->count) {
|
||||
size_t i;
|
||||
janet_array_ensure(array, count, 1);
|
||||
@ -104,7 +102,7 @@ void janet_array_setcount(JanetArray *array, size_t count) {
|
||||
|
||||
/* Push a value to the top of the array */
|
||||
void janet_array_push(JanetArray *array, Janet x) {
|
||||
if (array->count == INT32_MAX) {
|
||||
if (array->count == JANET_INTMAX_INT64) {
|
||||
janet_panic("array overflow");
|
||||
}
|
||||
size_t newcount = array->count + 1;
|
||||
@ -322,8 +320,6 @@ JANET_CORE_FN(cfun_array_remove,
|
||||
janet_panicf("removal index %d out of range [0,%d]", at, array->count);
|
||||
if (argc == 3) {
|
||||
n = janet_getsize(argv, 2);
|
||||
if (n < 0)
|
||||
janet_panicf("expected non-negative integer for argument n, got %v", argv[2]);
|
||||
}
|
||||
if (at + n > array->count) {
|
||||
n = array->count - at;
|
||||
|
@ -62,7 +62,6 @@ JanetBuffer *janet_buffer_init(JanetBuffer *buffer, size_t capacity) {
|
||||
|
||||
/* Initialize an unmanaged buffer */
|
||||
JanetBuffer *janet_pointer_buffer_unsafe(void *memory, size_t capacity, size_t count) {
|
||||
if (count < 0) janet_panic("count < 0");
|
||||
if (capacity < count) janet_panic("capacity < count");
|
||||
JanetBuffer *buffer = janet_gcalloc(JANET_MEMORY_BUFFER, sizeof(JanetBuffer));
|
||||
buffer->gc.flags |= JANET_BUFFER_FLAG_NO_REALLOC;
|
||||
@ -104,8 +103,6 @@ void janet_buffer_ensure(JanetBuffer *buffer, size_t capacity, size_t growth) {
|
||||
|
||||
/* Ensure that the buffer has enough internal capacity */
|
||||
void janet_buffer_setcount(JanetBuffer *buffer, size_t count) {
|
||||
if (count < 0)
|
||||
return;
|
||||
if (count > buffer->count) {
|
||||
size_t oldcount = buffer->count;
|
||||
janet_buffer_ensure(buffer, count, 1);
|
||||
@ -210,7 +207,6 @@ JANET_CORE_FN(cfun_buffer_new_filled,
|
||||
"Returns the new buffer.") {
|
||||
janet_arity(argc, 1, 2);
|
||||
size_t count = janet_getsize(argv, 0);
|
||||
if (count < 0) count = 0;
|
||||
int32_t byte = 0;
|
||||
if (argc == 2) {
|
||||
byte = janet_getinteger(argv, 1) & 0xFF;
|
||||
@ -478,7 +474,7 @@ JANET_CORE_FN(cfun_buffer_push_at,
|
||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||
size_t index = janet_getsize(argv, 1);
|
||||
size_t old_count = buffer->count;
|
||||
if (index < 0 || index > old_count) {
|
||||
if (index > old_count) {
|
||||
janet_panicf("index out of range [0, %d)", old_count);
|
||||
}
|
||||
buffer->count = index;
|
||||
@ -518,7 +514,6 @@ JANET_CORE_FN(cfun_buffer_popn,
|
||||
janet_fixarity(argc, 2);
|
||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||
size_t n = janet_getsize(argv, 1);
|
||||
if (n < 0) janet_panic("n must be non-negative");
|
||||
if (buffer->count < n) {
|
||||
buffer->count = 0;
|
||||
} else {
|
||||
@ -620,7 +615,6 @@ JANET_CORE_FN(cfun_buffer_blit,
|
||||
if (!janet_checktype(argv[4], JANET_NIL))
|
||||
src_end = janet_gethalfrange(argv, 4, src.len, "src-end");
|
||||
length_src = src_end - offset_src;
|
||||
if (length_src < 0) length_src = 0;
|
||||
} else {
|
||||
length_src = src.len - offset_src;
|
||||
}
|
||||
|
@ -921,7 +921,7 @@ JANET_CORE_FN(cfun_parse_consume,
|
||||
JanetByteView view = janet_getbytes(argv, 1);
|
||||
if (argc == 3) {
|
||||
size_t offset = janet_getsize(argv, 2);
|
||||
if (offset < 0 || offset > view.len)
|
||||
if (offset > view.len)
|
||||
janet_panicf("invalid offset %d out of range [0,%d]", offset, view.len);
|
||||
view.len -= offset;
|
||||
view.bytes += offset;
|
||||
|
@ -583,7 +583,7 @@ static int32_t trim_help_leftedge(JanetByteView str, JanetByteView set) {
|
||||
}
|
||||
|
||||
static int32_t trim_help_rightedge(JanetByteView str, JanetByteView set) {
|
||||
for (size_t i = str.len - 1; i >= 0; i--)
|
||||
for (size_t i = str.len - 1; i > 0; i--)
|
||||
if (!trim_help_checkset(set, str.bytes[i]))
|
||||
return i + 1;
|
||||
return 0;
|
||||
|
@ -861,7 +861,7 @@ int32_t janet_sorted_keys(const JanetKV *dict, size_t cap, int32_t *index_buffer
|
||||
for (size_t i = 1; i < next_index; i++) {
|
||||
int32_t index_to_insert = index_buffer[i];
|
||||
Janet lhs = dict[index_to_insert].key;
|
||||
for (size_t j = i - 1; j >= 0; j--) {
|
||||
for (size_t j = i - 1; j > 0; j--) {
|
||||
index_buffer[j + 1] = index_buffer[j];
|
||||
Janet rhs = dict[index_buffer[j]].key;
|
||||
if (janet_compare(lhs, rhs) >= 0) {
|
||||
|
@ -179,7 +179,7 @@ Janet janet_next_impl(Janet ds, Janet key, int is_interpreter) {
|
||||
} else {
|
||||
len = janet_string_length(janet_unwrap_string(ds));
|
||||
}
|
||||
if (i < len && i >= 0) {
|
||||
if (i < len) {
|
||||
return janet_wrap_size(i);
|
||||
}
|
||||
break;
|
||||
@ -530,7 +530,6 @@ Janet janet_get(Janet ds, Janet key) {
|
||||
case JANET_KEYWORD: {
|
||||
if (!janet_checksize(key)) return janet_wrap_nil();
|
||||
size_t index = janet_unwrap_size(key);
|
||||
if (index < 0) return janet_wrap_nil();
|
||||
const uint8_t *str = janet_unwrap_string(ds);
|
||||
if (index >= janet_string_length(str)) return janet_wrap_nil();
|
||||
return janet_wrap_integer(str[index]);
|
||||
@ -549,7 +548,6 @@ Janet janet_get(Janet ds, Janet key) {
|
||||
case JANET_BUFFER: {
|
||||
if (!janet_checkint(key)) return janet_wrap_nil();
|
||||
size_t index = janet_unwrap_size(key);
|
||||
if (index < 0) return janet_wrap_nil();
|
||||
if (t == JANET_ARRAY) {
|
||||
JanetArray *a = janet_unwrap_array(ds);
|
||||
if (index >= a->count) return janet_wrap_nil();
|
||||
@ -584,7 +582,6 @@ Janet janet_get(Janet ds, Janet key) {
|
||||
|
||||
Janet janet_getindex(Janet ds, size_t index) {
|
||||
Janet value;
|
||||
if (index < 0) janet_panic("expected non-negative index");
|
||||
switch (janet_type(ds)) {
|
||||
default:
|
||||
janet_panicf("expected %T, got %v", JANET_TFLAG_LENGTHABLE, ds);
|
||||
|
Loading…
Reference in New Issue
Block a user