mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Use copy over intrinsics.mem_copy_non_overlapping
This commit is contained in:
+8
-10
@@ -1,6 +1,5 @@
|
|||||||
package os2
|
package os2
|
||||||
|
|
||||||
import "base:intrinsics"
|
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
@@ -163,7 +162,7 @@ clean_path :: proc(path: string, allocator: runtime.Allocator) -> (cleaned: stri
|
|||||||
}
|
}
|
||||||
case:
|
case:
|
||||||
// Copy the path element verbatim and add a separator.
|
// Copy the path element verbatim and add a separator.
|
||||||
intrinsics.mem_copy_non_overlapping(raw_data(buffer[buffer_i:]), raw_data(elem), len(elem))
|
copy(buffer[buffer_i:], elem)
|
||||||
buffer_i += len(elem)
|
buffer_i += len(elem)
|
||||||
buffer[buffer_i] = _Path_Separator
|
buffer[buffer_i] = _Path_Separator
|
||||||
buffer_i += 1
|
buffer_i += 1
|
||||||
@@ -182,7 +181,7 @@ clean_path :: proc(path: string, allocator: runtime.Allocator) -> (cleaned: stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
compact := make([]u8, buffer_i, allocator) or_return
|
compact := make([]u8, buffer_i, allocator) or_return
|
||||||
intrinsics.mem_copy_non_overlapping(raw_data(compact), raw_data(buffer), buffer_i)
|
copy(compact, buffer) // NOTE(bill): buffer[:buffer_i] is redundant here
|
||||||
return string(compact), nil
|
return string(compact), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +297,7 @@ get_relative_path :: proc(base, target: string, allocator: runtime.Allocator) ->
|
|||||||
buf[n] = _Path_Separator
|
buf[n] = _Path_Separator
|
||||||
n += 1
|
n += 1
|
||||||
}
|
}
|
||||||
runtime.mem_copy_non_overlapping(raw_data(buf[n:]), raw_data(trailing), len(trailing))
|
copy(buf[n:], trailing)
|
||||||
}
|
}
|
||||||
|
|
||||||
path = string(buf)
|
path = string(buf)
|
||||||
@@ -389,17 +388,16 @@ For example, `join_filename("foo", "tar.gz")` will result in `"foo.tar.gz"`.
|
|||||||
*/
|
*/
|
||||||
@(require_results)
|
@(require_results)
|
||||||
join_filename :: proc(base: string, ext: string, allocator: runtime.Allocator) -> (joined: string, err: Error) {
|
join_filename :: proc(base: string, ext: string, allocator: runtime.Allocator) -> (joined: string, err: Error) {
|
||||||
len_base := len(base)
|
if len(base) == 0 {
|
||||||
if len_base == 0 {
|
|
||||||
return strings.clone(ext, allocator)
|
return strings.clone(ext, allocator)
|
||||||
} else if len(ext) == 0 {
|
} else if len(ext) == 0 {
|
||||||
return strings.clone(base, allocator)
|
return strings.clone(base, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]u8, len_base + 1 + len(ext), allocator) or_return
|
buf := make([]u8, len(base) + 1 + len(ext), allocator) or_return
|
||||||
intrinsics.mem_copy_non_overlapping(raw_data(buf), raw_data(base), len_base)
|
copy(buf, base)
|
||||||
buf[len_base] = '.'
|
buf[len(base)] = '.'
|
||||||
intrinsics.mem_copy_non_overlapping(raw_data(buf[1+len_base:]), raw_data(ext), len(ext))
|
copy(buf[1+len(base):], ext)
|
||||||
|
|
||||||
return string(buf), nil
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#+private
|
#+private
|
||||||
package os2
|
package os2
|
||||||
|
|
||||||
import "base:intrinsics"
|
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import win32 "core:sys/windows"
|
import win32 "core:sys/windows"
|
||||||
@@ -271,7 +270,7 @@ _clean_path_handle_start :: proc(path: string, buffer: []u8) -> (rooted: bool, s
|
|||||||
// Take `C:` to `C:\`.
|
// Take `C:` to `C:\`.
|
||||||
start += 1
|
start += 1
|
||||||
}
|
}
|
||||||
intrinsics.mem_copy_non_overlapping(raw_data(buffer), raw_data(path), start)
|
copy(buffer, path[:start])
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user