From 1fd677b42e33cf0407e204830df656fc1a931df5 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 25 Mar 2019 21:29:21 +0000 Subject: [PATCH] Remove *_remove from demo and use built-in versions --- core/runtime/core.odin | 4 +++- core/runtime/internal.odin | 2 +- examples/demo/demo.odin | 14 -------------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 1ce7cfac5..187573557 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -403,7 +403,9 @@ unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_loca @builtin ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) { bounds_check_error_loc(loc, index, len(array)); - copy(array[index:], array[index+1:]); + if index+1 < len(array) { + copy(array[index:], array[index+1:]); + } pop(array); } diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 202f739b6..82cd4cb72 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -303,7 +303,7 @@ slice_expr_error_hi :: proc "contextless" (file: string, line, column: int, hi: } slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { - if 0 <= lo && lo < len && len <= hi && hi <= len do return; + if 0 <= lo && lo < len && lo <= hi && hi <= len do return; handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { fd := os.stderr; print_caller_location(fd, Source_Code_Location{file, line, column, "", 0}); diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index e5c5830e1..efce9299a 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -561,20 +561,6 @@ threading_example :: proc() { when os.OS == "windows" { fmt.println("# threading_example"); - unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) { - runtime.bounds_check_error_loc(loc, index, len(array)); - n := len(array)-1; - if index != n { - array[index] = array[n]; - } - pop(array); - } - ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) { - runtime.bounds_check_error_loc(loc, index, len(array)); - copy(array[index:], array[index+1:]); - pop(array); - } - worker_proc :: proc(t: ^thread.Thread) -> int { for iteration in 1..5 { fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration);