vec: switch to pointer to u8 instead of void pointer for vec_data
No issues with indexing this by byte, right?
This commit is contained in:
4
alisp.h
4
alisp.h
@@ -81,7 +81,7 @@ static_assert(sizeof(vec_t) == 64, "vec_t has to be 64 bytes as part of SBO");
|
||||
|
||||
void vec_init(vec_t *, u64);
|
||||
void vec_free(vec_t *);
|
||||
void *vec_data(vec_t *);
|
||||
u8 *vec_data(vec_t *);
|
||||
void vec_ensure_free(vec_t *, u64);
|
||||
void vec_append(vec_t *, const void *const, u64);
|
||||
void vec_clone(vec_t *, vec_t *);
|
||||
@@ -184,7 +184,7 @@ typedef struct
|
||||
/// System context
|
||||
typedef struct
|
||||
{
|
||||
vec_t conses;
|
||||
vec_t memory;
|
||||
sym_table_t symtable;
|
||||
} sys_t;
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ char stream_peek(stream_t *stream)
|
||||
// Cached already? We are done.
|
||||
if (stream->position < stream->pipe.cache.size)
|
||||
{
|
||||
const char *const str = vec_data(&stream->pipe.cache);
|
||||
const char *const str = (char *)vec_data(&stream->pipe.cache);
|
||||
return str[stream->position];
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ sv_t stream_substr(stream_t *stream, u64 size)
|
||||
break;
|
||||
case STREAM_TYPE_PIPE:
|
||||
case STREAM_TYPE_FILE:
|
||||
ptr = vec_data(&stream->pipe.cache);
|
||||
ptr = (char *)vec_data(&stream->pipe.cache);
|
||||
break;
|
||||
default:
|
||||
FAIL("Unreachable");
|
||||
@@ -323,7 +323,7 @@ sv_t stream_substr_abs(stream_t *stream, u64 index, u64 size)
|
||||
case STREAM_TYPE_FILE:
|
||||
{
|
||||
if (index + size <= stream_size(stream))
|
||||
return SV(vec_data(&stream->pipe.cache) + index, size);
|
||||
return SV((char *)vec_data(&stream->pipe.cache) + index, size);
|
||||
// (index + size > stream_size(stream)) => try reading chunks
|
||||
for (bool read_chunk = stream_chunk(stream);
|
||||
read_chunk && index + size >= stream->pipe.cache.size;
|
||||
@@ -332,7 +332,7 @@ sv_t stream_substr_abs(stream_t *stream, u64 index, u64 size)
|
||||
|
||||
if (index + size > stream_size(stream))
|
||||
return SV(NULL, 0);
|
||||
return SV(vec_data(&stream->pipe.cache) + index, size);
|
||||
return SV((char *)vec_data(&stream->pipe.cache) + index, size);
|
||||
}
|
||||
default:
|
||||
assert("Unreachable");
|
||||
|
||||
@@ -46,7 +46,7 @@ void vec_free(vec_t *vec)
|
||||
memset(vec, 0, sizeof(*vec));
|
||||
}
|
||||
|
||||
void *vec_data(vec_t *vec)
|
||||
u8 *vec_data(vec_t *vec)
|
||||
{
|
||||
return vec->not_inlined ? vec->ptr : vec->inlined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user