v.util: add an iabs(x) helper (#9172)
parent
4c7b6ce2fd
commit
45d51c76da
|
@ -568,11 +568,6 @@ pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) {
|
|||
f.comments(node.comments, has_nl: false)
|
||||
}
|
||||
|
||||
[inline]
|
||||
fn abs(v int) int {
|
||||
return if v >= 0 { v } else { -v }
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
|
||||
if node.is_pub {
|
||||
f.write('pub ')
|
||||
|
|
|
@ -75,7 +75,8 @@ fn (mut list []CommentAndExprAlignInfo) add_info(attrs_len int, type_len int, li
|
|||
list.add_new_info(attrs_len, type_len, line)
|
||||
return
|
||||
}
|
||||
d_len := abs(list[i].max_attrs_len - attrs_len) + abs(list[i].max_type_len - type_len)
|
||||
d_len := util.iabs(list[i].max_attrs_len - attrs_len) +
|
||||
util.iabs(list[i].max_type_len - type_len)
|
||||
if !(d_len < fmt.threshold_to_align_struct) {
|
||||
list.add_new_info(attrs_len, type_len, line)
|
||||
return
|
||||
|
|
|
@ -363,6 +363,11 @@ pub fn imax(a int, b int) int {
|
|||
return if a > b { a } else { b }
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn iabs(v int) int {
|
||||
return if v > 0 { v } else { -v }
|
||||
}
|
||||
|
||||
pub fn replace_op(s string) string {
|
||||
if s.len == 1 {
|
||||
last_char := s[s.len - 1]
|
||||
|
|
Loading…
Reference in New Issue