authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-09 08:58:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-10 20:53:57-04:00
log9e92dbdd0889a68e32cde85c1a07767200a9ad7e
tree3011d68e950e0e1305c7bc8cc65d9b0be2b38647
parent100990b052be249c23743140d19ced37d463b51d

std: use parameter type inference on min and max functions


5 files changed, 12 insertions(+), 10 deletions(-)

src/analyze.cpp+1-2
......@@ -988,6 +988,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
988988 case TypeTableEntryIdNullLit:
989989 case TypeTableEntryIdNamespace:
990990 case TypeTableEntryIdGenericFn:
991 case TypeTableEntryIdVar:
991992 fn_proto->skip = true;
992993 add_node_error(g, fn_proto->return_type,
993994 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
......@@ -1009,8 +1010,6 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
10091010 case TypeTableEntryIdFn:
10101011 case TypeTableEntryIdTypeDecl:
10111012 break;
1012 case TypeTableEntryIdVar:
1013 zig_panic("TODO var return type");
10141013 }
10151014
10161015
std/hash_map.zig+3-4
......@@ -180,8 +180,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
180180 if (entry.distance_from_start_index < distance_from_start_index) {
181181 // robin hood to the rescue
182182 const tmp = *entry;
183 hm.max_distance_from_start_index = math.max(usize,
184 hm.max_distance_from_start_index, distance_from_start_index);
183 hm.max_distance_from_start_index = math.max(hm.max_distance_from_start_index,
184 distance_from_start_index);
185185 *entry = Entry {
186186 .used = true,
187187 .distance_from_start_index = distance_from_start_index,
......@@ -201,8 +201,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
201201 hm.size += 1;
202202 }
203203
204 hm.max_distance_from_start_index = math.max(usize, distance_from_start_index,
205 hm.max_distance_from_start_index);
204 hm.max_distance_from_start_index = math.max(distance_from_start_index, hm.max_distance_from_start_index);
206205 *entry = Entry {
207206 .used = true,
208207 .distance_from_start_index = distance_from_start_index,
std/io.zig+1-1
......@@ -79,7 +79,7 @@ pub struct OutStream {
7979 const dest_space_left = os.buffer.len - os.index;
8080
8181 while (src_bytes_left > 0) {
82 const copy_amt = math.min(usize, dest_space_left, src_bytes_left);
82 const copy_amt = math.min(dest_space_left, src_bytes_left);
8383 @memcpy(&os.buffer[os.index], &bytes[src_index], copy_amt);
8484 os.index += copy_amt;
8585 if (os.index == os.buffer.len) {
std/math.zig+6-2
......@@ -4,11 +4,11 @@ pub enum Cmp {
44 Less,
55}
66
7pub fn min(inline T: type, x: T, y: T) -> T {
7pub fn min(x: var, y: var) -> @typeOf(x + y) {
88 if (x < y) x else y
99}
1010
11pub fn max(inline T: type, x: T, y: T) -> T {
11pub fn max(x: var, y: var) -> @typeOf(x + y) {
1212 if (x > y) x else y
1313}
1414
......@@ -25,3 +25,7 @@ pub fn subOverflow(inline T: type, a: T, b: T) -> %T {
2525 var answer: T = undefined;
2626 if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer
2727}
28pub fn shlOverflow(inline T: type, a: T, b: T) -> %T {
29 var answer: T = undefined;
30 if (@shlWithOverflow(T, a, b, &answer)) error.Overflow else answer
31}
std/mem.zig+1-1
......@@ -50,7 +50,7 @@ pub fn copy(inline T: type, dest: []T, source: []const T) {
5050/// Return < 0, == 0, or > 0 if memory a is less than, equal to, or greater than,
5151/// memory b, respectively.
5252pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp {
53 const n = math.min(usize, a.len, b.len);
53 const n = math.min(a.len, b.len);
5454 var i: usize = 0;
5555 while (i < n; i += 1) {
5656 if (a[i] == b[i]) continue;