Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdoc: cleanup node.v #21250

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions vlib/v/doc/node.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ pub const should_sort = os.getenv_opt('VDOC_SORT') or { 'true' }.bool()

pub fn (nodes []DocNode) find(symname string) !DocNode {
for node in nodes {
if node.name != symname {
continue
if node.name == symname {
return node
}
return node
}
return error('symbol not found')
}
Expand All @@ -29,15 +28,13 @@ pub fn (mut nodes []DocNode) sort_by_kind() {
}

fn compare_nodes_by_kind(a &DocNode, b &DocNode) int {
ak := int((*a).kind)
bk := int((*b).kind)
if ak < bk {
return -1
}
if ak > bk {
return 1
ak := int(a.kind)
bk := int(b.kind)
return match true {
ak < bk { -1 }
ak > bk { 1 }
else { 0 }
}
return 0
}

fn compare_nodes_by_name(a &DocNode, b &DocNode) int {
Expand All @@ -48,7 +45,7 @@ fn compare_nodes_by_name(a &DocNode, b &DocNode) int {

// arr() converts the map into an array of `DocNode`.
pub fn (cnts map[string]DocNode) arr() []DocNode {
mut contents := cnts.keys().map(cnts[it])
mut contents := cnts.values()
Comment on lines -51 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rg '\.keys\(\).map\(' returned a few more potential candidates:

#0 18:56:57 ᛋ master /v/oo❱rg '\.keys\(\).map\('
vlib/net/http/header.v:504:new_keys := arrays.distinct(h.keys().map(it.to_lower()))
vlib/v/doc/node.v:51:mut contents := cnts.keys().map(cnts[it])
vlib/v/tests/map_literals_method_call_test.v:4:}.keys().map({
vlib/v/tests/bench/math_big_gcd/prime/maker.v:176:return tmp.keys().map(tmp[it])
cmd/tools/vdoc/vdoc.v:64:jw.write_string(json.encode(d.contents.keys().map(d.contents[it])))
#0 16:21:05 ᛋ master /v/oo❱

contents.sort_by_name()
contents.sort_by_kind()
return contents
Expand Down