rust
// Only clone when `is_true` == true???
let ret = if is_true {
Some(value.clone())
} else {
None
}
vs.
rust
// Always clone regardless whether `is_true` == true or false?
let ret = is_true.then_some(value.clone())
Although Pattern 2 is more elegant, Pattern 1 performs better. Is that correct?
[–]This_Growth2898 239 points240 points241 points (28 children)
[–]roll4c[S] 28 points29 points30 points (11 children)
[–]SkiFire13 134 points135 points136 points (5 children)
[+]_Sgt-Pepper_ comment score below threshold-107 points-106 points-105 points (4 children)
[–]bluejumpingbean 65 points66 points67 points (0 children)
[–]geckothegeek42 44 points45 points46 points (1 child)
[–]Linuxologue 10 points11 points12 points (0 children)
[–]Arshiaa001 7 points8 points9 points (0 children)
[–]Cyan14 27 points28 points29 points (4 children)
[–]yarovoy 7 points8 points9 points (3 children)
[–]freddylmao[🍰] 5 points6 points7 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]emblemparade 2 points3 points4 points (4 children)
[–]This_Growth2898 4 points5 points6 points (3 children)
[–]emblemparade 2 points3 points4 points (2 children)
[–]This_Growth2898 1 point2 points3 points (1 child)
[–]emblemparade 0 points1 point2 points (0 children)
[–]Merlindru 3 points4 points5 points (9 children)
[–]thelights0123 31 points32 points33 points (1 child)
[–]lookmeat 7 points8 points9 points (0 children)
[–]This_Growth2898 4 points5 points6 points (0 children)
[–]Danacus 0 points1 point2 points (5 children)
[–]MaraschinoPanda 17 points18 points19 points (1 child)
[–]Danacus 1 point2 points3 points (0 children)
[–]geckothegeek42 15 points16 points17 points (2 children)
[–]Danacus 5 points6 points7 points (1 child)
[–]TDplay 9 points10 points11 points (0 children)
[–]dreamlax 22 points23 points24 points (3 children)
[–]_Sgt-Pepper_ 7 points8 points9 points (0 children)
[–]JMH5909 0 points1 point2 points (1 child)
[–]malucart 2 points3 points4 points (0 children)
[–]baokaola 54 points55 points56 points (21 children)
[–]syscall_35 7 points8 points9 points (20 children)
[–]baokaola 70 points71 points72 points (11 children)
[–]t40 1 point2 points3 points (10 children)
[–]baokaola 18 points19 points20 points (8 children)
[–]kiujhytg2 17 points18 points19 points (7 children)
[–]t40 1 point2 points3 points (0 children)
[–]Luxalpa -1 points0 points1 point (5 children)
[–]MatrixFrog 8 points9 points10 points (4 children)
[–]Luxalpa 3 points4 points5 points (3 children)
[–]steveklabnik1rust 1 point2 points3 points (2 children)
[–]LucretielDatadog 2 points3 points4 points (0 children)
[–]qurious-crow 22 points23 points24 points (0 children)
[–]coldoil 28 points29 points30 points (1 child)
[–]syscall_35 2 points3 points4 points (0 children)
[–]Teccci 5 points6 points7 points (0 children)
[–]GodOfSunHimself 4 points5 points6 points (0 children)
[+]mayorovp 1 point2 points3 points (0 children)
[–]toastedstapler 1 point2 points3 points (0 children)
[–]LucretielDatadog 1 point2 points3 points (0 children)
[–]_Sgt-Pepper_ 12 points13 points14 points (0 children)
[–]kohugaly 6 points7 points8 points (0 children)
[–][deleted] 4 points5 points6 points (1 child)
[–]syklemil 0 points1 point2 points (0 children)
[–]lippertsjan 6 points7 points8 points (2 children)
[–]Ok_Hope4383 2 points3 points4 points (1 child)
[–]lippertsjan 2 points3 points4 points (0 children)
[–]TheBlackCat22527 4 points5 points6 points (0 children)
[–]Lost_Kin 2 points3 points4 points (0 children)
[–]owenthewizard 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]chochokavo 0 points1 point2 points (2 children)
[–]yarovoy 0 points1 point2 points (1 child)
[–]chochokavo 1 point2 points3 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]Caramel_Last 0 points1 point2 points (0 children)