Skip to content

Commit 884db00

Browse files
committed
fix: early return from std.set
1 parent 7a424b0 commit 884db00

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

crates/jrsonnet-stdlib/src/sort.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn sort_identity(mut values: Vec<Val>) -> Result<Vec<Val>> {
5757
Val::Str(s) => s.clone(),
5858
_ => unreachable!(),
5959
}),
60-
SortKeyType::Unknown => unreachable!(),
60+
SortKeyType::Unknown => unreachable!("list is not empty, as checked in sort"),
6161
};
6262
Ok(values)
6363
}
@@ -81,7 +81,7 @@ fn sort_keyf(values: ArrValue, keyf: FuncVal) -> Result<Vec<Thunk<Val>>> {
8181
Val::Str(s) => s.clone(),
8282
_ => unreachable!(),
8383
}),
84-
SortKeyType::Unknown => unreachable!(),
84+
SortKeyType::Unknown => unreachable!("list is not empty, as checked in sort"),
8585
};
8686
Ok(vk.into_iter().map(|v| v.0).collect())
8787
}
@@ -103,13 +103,7 @@ pub fn sort(values: ArrValue, key_getter: FuncVal) -> Result<ArrValue> {
103103
#[builtin]
104104
#[allow(non_snake_case)]
105105
pub fn builtin_sort(arr: ArrValue, keyF: Option<FuncVal>) -> Result<ArrValue> {
106-
if arr.len() <= 1 {
107-
return Ok(arr);
108-
}
109-
super::sort::sort(
110-
arr,
111-
keyF.unwrap_or_else(FuncVal::identity),
112-
)
106+
super::sort::sort(arr, keyF.unwrap_or_else(FuncVal::identity))
113107
}
114108

115109
fn uniq_identity(arr: Vec<Val>) -> Result<Vec<Val>> {
@@ -160,6 +154,9 @@ pub fn builtin_uniq(arr: ArrValue, keyF: Option<FuncVal>) -> Result<ArrValue> {
160154
#[builtin]
161155
#[allow(non_snake_case)]
162156
pub fn builtin_set(arr: ArrValue, keyF: Option<FuncVal>) -> Result<ArrValue> {
157+
if arr.len() <= 1 {
158+
return Ok(arr);
159+
}
163160
let keyF = keyF.unwrap_or(FuncVal::identity());
164161
if keyF.is_identity() {
165162
let arr = arr.iter().collect::<Result<Vec<Val>>>()?;

0 commit comments

Comments
 (0)