@@ -5445,8 +5445,8 @@ typedef struct lfs3_bcommit {
54455445 struct {
54465446 lfs3_rattr_t rattrs [4 ];
54475447 lfs3_data_t split_name ;
5448- uint8_t branch_l_buf [LFS3_BRANCH_DSIZE ];
5449- uint8_t branch_r_buf [LFS3_BRANCH_DSIZE ];
5448+ uint8_t l_buf [LFS3_BRANCH_DSIZE ];
5449+ uint8_t r_buf [LFS3_BRANCH_DSIZE ];
54505450 } ctx ;
54515451} lfs3_bcommit_t ;
54525452#endif
@@ -5602,12 +5602,15 @@ static int lfs3_btree_commit_(lfs3_t *lfs3,
56025602 // end up removing an rbyd here
56035603 bcommit -> bid -= pid - (child .weight - 1 );
56045604 lfs3_size_t rattr_count = 0 ;
5605+ lfs3_data_t branch ;
5606+ // drop child?
56055607 if (child_ -> weight == 0 ) {
5608+ // drop child
56065609 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR (
56075610 LFS3_TAG_RM , - child .weight );
56085611 } else {
5609- lfs3_data_t branch = lfs3_data_frombranch (
5610- child_ , bcommit -> ctx .branch_l_buf );
5612+ // update child
5613+ branch = lfs3_data_frombranch ( child_ , bcommit -> ctx .l_buf );
56115614 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR_BUF (
56125615 LFS3_TAG_BRANCH , 0 ,
56135616 branch .u .buffer , lfs3_data_size (branch ));
@@ -5941,46 +5944,36 @@ static int lfs3_btree_commit_(lfs3_t *lfs3,
59415944 // prepare commit to parent, tail recursing upwards
59425945 LFS3_ASSERT (child_ -> weight > 0 );
59435946 LFS3_ASSERT (sibling .weight > 0 );
5944- // new root?
5947+ // don't worry about bid if new root, we discard it anyways
5948+ bcommit -> bid -= pid - (child .weight - 1 );
59455949 rattr_count = 0 ;
5950+ branch = lfs3_data_frombranch (child_ , bcommit -> ctx .l_buf );
5951+ // new root?
59465952 if (!lfs3_rbyd_trunk (& parent )) {
5947- lfs3_data_t branch_l = lfs3_data_frombranch (
5948- child_ , bcommit -> ctx .branch_l_buf );
5953+ // new child
59495954 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR_BUF (
59505955 LFS3_TAG_BRANCH , + child_ -> weight ,
5951- branch_l .u .buffer , lfs3_data_size (branch_l ));
5952- lfs3_data_t branch_r = lfs3_data_frombranch (
5953- & sibling , bcommit -> ctx .branch_r_buf );
5954- bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR_BUF (
5955- LFS3_TAG_BRANCH , + sibling .weight ,
5956- branch_r .u .buffer , lfs3_data_size (branch_r ));
5957- if (lfs3_tag_suptype (split_tag ) == LFS3_TAG_NAME ) {
5958- bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR_DATA (
5959- LFS3_TAG_BNAME , 0 ,
5960- & bcommit -> ctx .split_name );
5961- }
5956+ branch .u .buffer , lfs3_data_size (branch ));
59625957 // split root?
59635958 } else {
5964- bcommit -> bid -= pid - (child .weight - 1 );
5965- lfs3_data_t branch_l = lfs3_data_frombranch (
5966- child_ , bcommit -> ctx .branch_l_buf );
5959+ // update child
59675960 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR_BUF (
59685961 LFS3_TAG_BRANCH , 0 ,
5969- branch_l .u .buffer , lfs3_data_size (branch_l ));
5962+ branch .u .buffer , lfs3_data_size (branch ));
59705963 if (child_ -> weight != child .weight ) {
59715964 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR (
59725965 LFS3_TAG_GROW , - child .weight + child_ -> weight );
59735966 }
5974- lfs3_data_t branch_r = lfs3_data_frombranch (
5975- & sibling , bcommit -> ctx . branch_r_buf );
5976- bcommit -> ctx .rattrs [ rattr_count ++ ] = LFS3_RATTR_BUF (
5977- LFS3_TAG_BRANCH , + sibling . weight ,
5978- branch_r . u . buffer , lfs3_data_size ( branch_r ));
5979- if ( lfs3_tag_suptype ( split_tag ) == LFS3_TAG_NAME ) {
5980- bcommit -> ctx . rattrs [ rattr_count ++ ] = LFS3_RATTR_DATA (
5981- LFS3_TAG_BNAME , 0 ,
5982- & bcommit -> ctx . split_name );
5983- }
5967+ }
5968+ // new sibling
5969+ branch = lfs3_data_frombranch ( & sibling , bcommit -> ctx .r_buf );
5970+ bcommit -> ctx . rattrs [ rattr_count ++ ] = LFS3_RATTR_BUF (
5971+ LFS3_TAG_BRANCH , + sibling . weight ,
5972+ branch . u . buffer , lfs3_data_size ( branch ));
5973+ if ( lfs3_tag_suptype ( split_tag ) == LFS3_TAG_NAME ) {
5974+ bcommit -> ctx . rattrs [ rattr_count ++ ] = LFS3_RATTR_DATA (
5975+ LFS3_TAG_BNAME , 0 ,
5976+ & bcommit -> ctx . split_name );
59845977 }
59855978 LFS3_ASSERT (rattr_count
59865979 <= sizeof (bcommit -> ctx .rattrs )
@@ -6069,13 +6062,13 @@ static int lfs3_btree_commit_(lfs3_t *lfs3,
60696062
60706063 // prepare commit to parent, tail recursing upwards
60716064 LFS3_ASSERT (child_ -> weight > 0 );
6072- // build attr list
60736065 bcommit -> bid -= pid - (child .weight - 1 );
60746066 rattr_count = 0 ;
6067+ // merge sibling
60756068 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR (
60766069 LFS3_TAG_RM , - sibling .weight );
6077- lfs3_data_t branch = lfs3_data_frombranch (
6078- child_ , bcommit -> ctx .branch_l_buf );
6070+ // update child
6071+ branch = lfs3_data_frombranch ( child_ , bcommit -> ctx .l_buf );
60796072 bcommit -> ctx .rattrs [rattr_count ++ ] = LFS3_RATTR_BUF (
60806073 LFS3_TAG_BRANCH , 0 ,
60816074 branch .u .buffer , lfs3_data_size (branch ));
0 commit comments