mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 09:54:45 +00:00
Use multi-pointers when appropriate
This commit is contained in:
@@ -135,16 +135,15 @@ ptr_sub :: proc(a, b: $P/^$T) -> int {
|
||||
}
|
||||
|
||||
slice_ptr :: proc(ptr: ^$T, len: int) -> []T {
|
||||
assert(len >= 0);
|
||||
return transmute([]T)Raw_Slice{data = ptr, len = len};
|
||||
return ([^]T)(ptr)[:len];
|
||||
}
|
||||
|
||||
byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
|
||||
return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
|
||||
return ([^]u8)(data)[:max(len, 0)];
|
||||
}
|
||||
@(deprecated="use byte_slice")
|
||||
slice_ptr_to_bytes :: proc(data: rawptr, len: int) -> []byte {
|
||||
return transmute([]u8)Raw_Slice{data=data, len=max(len, 0)};
|
||||
return ([^]u8)(data)[:max(len, 0)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -65,22 +65,19 @@ unset_env :: proc(key: string) -> Errno {
|
||||
// environ returns a copy of strings representing the environment, in the form "key=value"
|
||||
// NOTE: the slice of strings and the strings with be allocated using the supplied allocator
|
||||
environ :: proc(allocator := context.allocator) -> []string {
|
||||
envs := win32.GetEnvironmentStringsW();
|
||||
envs := cast([^]win32.WCHAR)(win32.GetEnvironmentStringsW());
|
||||
if envs == nil {
|
||||
return nil;
|
||||
}
|
||||
defer win32.FreeEnvironmentStringsW(envs);
|
||||
|
||||
r := make([dynamic]string, 0, 50, allocator);
|
||||
for from, i, p := 0, 0, envs; true; i += 1 {
|
||||
c := (^u16)(uintptr(p) + uintptr(i*2))^;
|
||||
if c == 0 {
|
||||
for from, i := 0, 0; true; i += 1 {
|
||||
if c := envs[i]; c == 0 {
|
||||
if i <= from {
|
||||
break;
|
||||
}
|
||||
w := mem.slice_ptr(mem.ptr_offset(p, from), i-from);
|
||||
|
||||
append(&r, win32.utf16_to_utf8(w, allocator));
|
||||
append(&r, win32.utf16_to_utf8(envs[from:i], allocator));
|
||||
from = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,9 +303,9 @@ append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) {
|
||||
if cap(array)-len(array) > 0 {
|
||||
a := (^Raw_Dynamic_Array)(array);
|
||||
when size_of(E) != 0 {
|
||||
data := (^E)(a.data);
|
||||
data := ([^]E)(a.data);
|
||||
assert(condition=data != nil, loc=loc);
|
||||
intrinsics.ptr_offset(data, a.len)^ = arg;
|
||||
data[a.len] = arg;
|
||||
}
|
||||
a.len += 1;
|
||||
}
|
||||
@@ -331,9 +331,9 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
|
||||
if arg_len > 0 {
|
||||
a := (^Raw_Dynamic_Array)(array);
|
||||
when size_of(E) != 0 {
|
||||
data := (^E)(a.data);
|
||||
data := ([^]E)(a.data);
|
||||
assert(condition=data != nil, loc=loc);
|
||||
intrinsics.mem_copy(intrinsics.ptr_offset(data, a.len), &args[0], size_of(E) * arg_len);
|
||||
intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len);
|
||||
}
|
||||
a.len += arg_len;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ LONG64 :: i64;
|
||||
PDWORD_PTR :: ^DWORD_PTR;
|
||||
ATOM :: distinct WORD;
|
||||
|
||||
wstring :: ^WCHAR;
|
||||
wstring :: [^]WCHAR;
|
||||
|
||||
PBYTE :: ^BYTE;
|
||||
LPBYTE :: ^BYTE;
|
||||
|
||||
Reference in New Issue
Block a user