@@ -41,7 +41,16 @@ impl PlaceExprSubSegment {
4141#[ derive( Eq , PartialEq , Debug , get_size2:: GetSize ) ]
4242pub struct PlaceExpr {
4343 root_name : Name ,
44- sub_segments : SmallVec < [ PlaceExprSubSegment ; 1 ] > ,
44+ #[ get_size( size_fn=sub_segments_size) ]
45+ sub_segments : thin_vec:: ThinVec < PlaceExprSubSegment > ,
46+ }
47+
48+ fn sub_segments_size ( segments : & thin_vec:: ThinVec < PlaceExprSubSegment > ) -> usize {
49+ segments. capacity ( ) * std:: mem:: size_of :: < PlaceExprSubSegment > ( )
50+ + segments
51+ . iter ( )
52+ . map ( get_size2:: GetSize :: get_heap_size)
53+ . sum :: < usize > ( )
4554}
4655
4756impl std:: fmt:: Display for PlaceExpr {
@@ -162,10 +171,10 @@ impl TryFrom<ast::ExprRef<'_>> for PlaceExpr {
162171}
163172
164173impl PlaceExpr {
165- pub ( crate ) const fn name ( name : Name ) -> Self {
174+ pub ( crate ) fn name ( name : Name ) -> Self {
166175 Self {
167176 root_name : name,
168- sub_segments : SmallVec :: new_const ( ) ,
177+ sub_segments : thin_vec :: ThinVec :: new ( ) ,
169178 }
170179 }
171180
@@ -652,6 +661,8 @@ pub struct PlaceTable {
652661impl PlaceTable {
653662 fn shrink_to_fit ( & mut self ) {
654663 self . places . shrink_to_fit ( ) ;
664+ self . place_set
665+ . shrink_to_fit ( |id| PlaceTable :: hash_place_expr ( & self . places [ * id] . expr ) ) ;
655666 }
656667
657668 pub ( crate ) fn place_expr ( & self , place_id : impl Into < ScopedPlaceId > ) -> & PlaceExprWithFlags {
@@ -775,7 +786,7 @@ impl std::fmt::Debug for PlaceTable {
775786pub ( super ) struct PlaceTableBuilder {
776787 table : PlaceTable ,
777788
778- associated_place_ids : IndexVec < ScopedPlaceId , Vec < ScopedPlaceId > > ,
789+ associated_place_ids : IndexVec < ScopedPlaceId , SmallVec < [ ScopedPlaceId ; 4 ] > > ,
779790}
780791
781792impl PlaceTableBuilder {
@@ -794,14 +805,17 @@ impl PlaceTableBuilder {
794805
795806 let id = self . table . places . push ( symbol) ;
796807 entry. insert ( id) ;
797- let new_id = self . associated_place_ids . push ( vec ! [ ] ) ;
808+ let new_id = self . associated_place_ids . push ( SmallVec :: new_const ( ) ) ;
798809 debug_assert_eq ! ( new_id, id) ;
799810 ( id, true )
800811 }
801812 }
802813 }
803814
804- pub ( super ) fn add_place ( & mut self , place_expr : PlaceExprWithFlags ) -> ( ScopedPlaceId , bool ) {
815+ pub ( super ) fn add_place (
816+ & mut self ,
817+ mut place_expr : PlaceExprWithFlags ,
818+ ) -> ( ScopedPlaceId , bool ) {
805819 let hash = PlaceTable :: hash_place_expr ( & place_expr. expr ) ;
806820 let entry = self . table . place_set . entry (
807821 hash,
@@ -812,9 +826,10 @@ impl PlaceTableBuilder {
812826 match entry {
813827 Entry :: Occupied ( entry) => ( * entry. get ( ) , false ) ,
814828 Entry :: Vacant ( entry) => {
829+ place_expr. expr . sub_segments . shrink_to_fit ( ) ;
815830 let id = self . table . places . push ( place_expr) ;
816831 entry. insert ( id) ;
817- let new_id = self . associated_place_ids . push ( vec ! [ ] ) ;
832+ let new_id = self . associated_place_ids . push ( SmallVec :: new_const ( ) ) ;
818833 debug_assert_eq ! ( new_id, id) ;
819834 for root in self . table . places [ id] . expr . root_exprs ( ) {
820835 if let Some ( root_id) = self . table . place_id_by_expr ( root) {
0 commit comments