vdoc: cleanup node.v (#21250)

This commit is contained in:
Turiiya 2024-04-11 15:23:44 +02:00 committed by GitHub
parent 6be2717680
commit 6dc417e662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,10 +6,9 @@ pub const should_sort = os.getenv_opt('VDOC_SORT') or { 'true' }.bool()
pub fn (nodes []DocNode) find(symname string) !DocNode { pub fn (nodes []DocNode) find(symname string) !DocNode {
for node in nodes { for node in nodes {
if node.name != symname { if node.name == symname {
continue return node
} }
return node
} }
return error('symbol not found') return error('symbol not found')
} }
@ -29,15 +28,13 @@ pub fn (mut nodes []DocNode) sort_by_kind() {
} }
fn compare_nodes_by_kind(a &DocNode, b &DocNode) int { fn compare_nodes_by_kind(a &DocNode, b &DocNode) int {
ak := int((*a).kind) ak := int(a.kind)
bk := int((*b).kind) bk := int(b.kind)
if ak < bk { return match true {
return -1 ak < bk { -1 }
ak > bk { 1 }
else { 0 }
} }
if ak > bk {
return 1
}
return 0
} }
fn compare_nodes_by_name(a &DocNode, b &DocNode) int { fn compare_nodes_by_name(a &DocNode, b &DocNode) int {
@ -48,7 +45,7 @@ fn compare_nodes_by_name(a &DocNode, b &DocNode) int {
// arr() converts the map into an array of `DocNode`. // arr() converts the map into an array of `DocNode`.
pub fn (cnts map[string]DocNode) arr() []DocNode { pub fn (cnts map[string]DocNode) arr() []DocNode {
mut contents := cnts.keys().map(cnts[it]) mut contents := cnts.values()
contents.sort_by_name() contents.sort_by_name()
contents.sort_by_kind() contents.sort_by_kind()
return contents return contents