Skip to content

Commit fb0d8e5

Browse files
committed
Adopted lfs3_bptr_slice for in-place bptr slicing
Helps with readability when we want to mutably slice a bptr. Also saves a bit of code: code stack ctx before: 36936 2384 652 after: 36860 (-0.2%) 2384 (+0.0%) 652 (+0.0%)
1 parent 0828fd9 commit fb0d8e5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lfs3.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,12 @@ static inline uint32_t lfs3_bptr_cksum(const lfs3_bptr_t *bptr) {
24992499
}
25002500
#endif
25012501

2502+
// slice a bptr in-place
2503+
static inline void lfs3_bptr_slice(lfs3_bptr_t *bptr,
2504+
lfs3_ssize_t off, lfs3_ssize_t size) {
2505+
bptr->d = lfs3_data_slice(bptr->d, off, size);
2506+
}
2507+
25022508
// bptr on-disk encoding
25032509
#if !defined(LFS3_RDONLY) && !defined(LFS3_2BONLY)
25042510
static lfs3_data_t lfs3_data_frombptr(const lfs3_bptr_t *bptr,
@@ -2617,7 +2623,7 @@ static int lfs3_bptr_fetch(lfs3_t *lfs3, lfs3_bptr_t *bptr,
26172623

26182624
// limit bptrs to btree weights, this may be useful for
26192625
// compression in the future
2620-
bptr->d = lfs3_data_slice(bptr->d, -1, weight);
2626+
lfs3_bptr_slice(bptr, -1, weight);
26212627

26222628
// checking fetches?
26232629
#ifdef LFS3_CKFETCHES
@@ -12315,11 +12321,11 @@ static int lfs3_file_graft_(lfs3_t *lfs3, lfs3_file_t *file,
1231512321

1231612322
// note, an entry can be both a left and right sibling
1231712323
l = bptr_;
12318-
l.d = lfs3_data_slice(bptr_.d,
12324+
lfs3_bptr_slice(&l,
1231912325
-1,
1232012326
pos - (bid-(weight_-1)));
1232112327
r = bptr_;
12322-
r.d = lfs3_data_slice(bptr_.d,
12328+
lfs3_bptr_slice(&r,
1232312329
pos+weight - (bid-(weight_-1)),
1232412330
-1);
1232512331

@@ -13942,7 +13948,7 @@ int lfs3_file_truncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size_) {
1394213948
//
1394313949
// note we don't unconditionally discard to match fruncate, where we
1394413950
// _really_ don't want to discard erased-state
13945-
file->leaf.bptr.d = lfs3_data_slice(file->leaf.bptr.d,
13951+
lfs3_bptr_slice(&file->leaf.bptr,
1394613952
-1,
1394713953
size_ - lfs3_min(file->leaf.pos, size_));
1394813954
file->leaf.weight = lfs3_min(
@@ -14025,7 +14031,7 @@ int lfs3_file_fruncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size_) {
1402514031
// note we _really_ don't want to discard erased-state if possible,
1402614032
// as fruncate is intended for logging operations, otherwise we'd
1402714033
// just unconditionally discard the leaf and avoid this hassle
14028-
file->leaf.bptr.d = lfs3_data_slice(file->leaf.bptr.d,
14034+
lfs3_bptr_slice(&file->leaf.bptr,
1402914035
lfs3_min(
1403014036
lfs3_smax(
1403114037
size - size_ - file->leaf.pos,

0 commit comments

Comments
 (0)