File tree Expand file tree Collapse file tree 1 file changed +12
-24
lines changed
frameworks/keyed/leptos/src Expand file tree Collapse file tree 1 file changed +12
-24
lines changed Original file line number Diff line number Diff line change @@ -50,30 +50,18 @@ static ID_COUNTER: AtomicUsize = AtomicUsize::new(1);
5050fn build_data ( count : usize ) -> Vec < RowData > {
5151 let mut thread_rng = thread_rng ( ) ;
5252
53- let mut data = Vec :: new ( ) ;
54- data. reserve_exact ( count) ;
55-
56- for _i in 0 ..count {
57- let adjective = ADJECTIVES . choose ( & mut thread_rng) . unwrap ( ) ;
58- let colour = COLOURS . choose ( & mut thread_rng) . unwrap ( ) ;
59- let noun = NOUNS . choose ( & mut thread_rng) . unwrap ( ) ;
60- let capacity = adjective. len ( ) + colour. len ( ) + noun. len ( ) + 2 ;
61- let mut label = String :: with_capacity ( capacity) ;
62- label. push_str ( adjective) ;
63- label. push ( ' ' ) ;
64- label. push_str ( colour) ;
65- label. push ( ' ' ) ;
66- label. push_str ( noun) ;
67-
68- data. push ( RowData {
69- id : ID_COUNTER . load ( Ordering :: Relaxed ) ,
70- label : ArcRwSignal :: new ( label) ,
71- } ) ;
72-
73- ID_COUNTER . store ( ID_COUNTER . load ( Ordering :: Relaxed ) + 1 , Ordering :: Relaxed ) ;
74- }
75-
76- data
53+ let mut label = || [ ADJECTIVES , COLOURS , NOUNS ]
54+ . map ( |slice| slice. choose ( & mut thread_rng) . unwrap ( ) )
55+ . join ( " " ) ;
56+
57+ let id = ID_COUNTER . fetch_add ( count, Ordering :: Relaxed ) ;
58+
59+ ( id..id + count)
60+ . map ( |id| RowData {
61+ id,
62+ label : ArcRwSignal :: new ( label ( ) )
63+ } )
64+ . collect ( )
7765}
7866
7967/// Button component.
You can’t perform that action at this time.
0 commit comments