std: use parameter type inference on min and max functions
This commit is contained in:
parent
100990b052
commit
9e92dbdd08
@ -988,6 +988,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
|
|||||||
case TypeTableEntryIdNullLit:
|
case TypeTableEntryIdNullLit:
|
||||||
case TypeTableEntryIdNamespace:
|
case TypeTableEntryIdNamespace:
|
||||||
case TypeTableEntryIdGenericFn:
|
case TypeTableEntryIdGenericFn:
|
||||||
|
case TypeTableEntryIdVar:
|
||||||
fn_proto->skip = true;
|
fn_proto->skip = true;
|
||||||
add_node_error(g, fn_proto->return_type,
|
add_node_error(g, fn_proto->return_type,
|
||||||
buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
|
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
|
|||||||
case TypeTableEntryIdFn:
|
case TypeTableEntryIdFn:
|
||||||
case TypeTableEntryIdTypeDecl:
|
case TypeTableEntryIdTypeDecl:
|
||||||
break;
|
break;
|
||||||
case TypeTableEntryIdVar:
|
|
||||||
zig_panic("TODO var return type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,8 +180,8 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
|
|||||||
if (entry.distance_from_start_index < distance_from_start_index) {
|
if (entry.distance_from_start_index < distance_from_start_index) {
|
||||||
// robin hood to the rescue
|
// robin hood to the rescue
|
||||||
const tmp = *entry;
|
const tmp = *entry;
|
||||||
hm.max_distance_from_start_index = math.max(usize,
|
hm.max_distance_from_start_index = math.max(hm.max_distance_from_start_index,
|
||||||
hm.max_distance_from_start_index, distance_from_start_index);
|
distance_from_start_index);
|
||||||
*entry = Entry {
|
*entry = Entry {
|
||||||
.used = true,
|
.used = true,
|
||||||
.distance_from_start_index = distance_from_start_index,
|
.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
|
|||||||
hm.size += 1;
|
hm.size += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hm.max_distance_from_start_index = math.max(usize, distance_from_start_index,
|
hm.max_distance_from_start_index = math.max(distance_from_start_index, hm.max_distance_from_start_index);
|
||||||
hm.max_distance_from_start_index);
|
|
||||||
*entry = Entry {
|
*entry = Entry {
|
||||||
.used = true,
|
.used = true,
|
||||||
.distance_from_start_index = distance_from_start_index,
|
.distance_from_start_index = distance_from_start_index,
|
||||||
|
@ -79,7 +79,7 @@ pub struct OutStream {
|
|||||||
const dest_space_left = os.buffer.len - os.index;
|
const dest_space_left = os.buffer.len - os.index;
|
||||||
|
|
||||||
while (src_bytes_left > 0) {
|
while (src_bytes_left > 0) {
|
||||||
const copy_amt = math.min(usize, dest_space_left, src_bytes_left);
|
const copy_amt = math.min(dest_space_left, src_bytes_left);
|
||||||
@memcpy(&os.buffer[os.index], &bytes[src_index], copy_amt);
|
@memcpy(&os.buffer[os.index], &bytes[src_index], copy_amt);
|
||||||
os.index += copy_amt;
|
os.index += copy_amt;
|
||||||
if (os.index == os.buffer.len) {
|
if (os.index == os.buffer.len) {
|
||||||
|
@ -4,11 +4,11 @@ pub enum Cmp {
|
|||||||
Less,
|
Less,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn min(inline T: type, x: T, y: T) -> T {
|
pub fn min(x: var, y: var) -> @typeOf(x + y) {
|
||||||
if (x < y) x else y
|
if (x < y) x else y
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max(inline T: type, x: T, y: T) -> T {
|
pub fn max(x: var, y: var) -> @typeOf(x + y) {
|
||||||
if (x > y) x else y
|
if (x > y) x else y
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,3 +25,7 @@ pub fn subOverflow(inline T: type, a: T, b: T) -> %T {
|
|||||||
var answer: T = undefined;
|
var answer: T = undefined;
|
||||||
if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer
|
if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer
|
||||||
}
|
}
|
||||||
|
pub fn shlOverflow(inline T: type, a: T, b: T) -> %T {
|
||||||
|
var answer: T = undefined;
|
||||||
|
if (@shlWithOverflow(T, a, b, &answer)) error.Overflow else answer
|
||||||
|
}
|
||||||
|
@ -50,7 +50,7 @@ pub fn copy(inline T: type, dest: []T, source: []const T) {
|
|||||||
/// Return < 0, == 0, or > 0 if memory a is less than, equal to, or greater than,
|
/// Return < 0, == 0, or > 0 if memory a is less than, equal to, or greater than,
|
||||||
/// memory b, respectively.
|
/// memory b, respectively.
|
||||||
pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp {
|
pub fn cmp(inline T: type, a: []const T, b: []const T) -> Cmp {
|
||||||
const n = math.min(usize, a.len, b.len);
|
const n = math.min(a.len, b.len);
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < n; i += 1) {
|
while (i < n; i += 1) {
|
||||||
if (a[i] == b[i]) continue;
|
if (a[i] == b[i]) continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user