On 2022/11/19 2:06, Kang-Che Sung wrote:


On Friday, November 18, 2022, Xiaoming Ni <[email protected] <mailto:[email protected]>> wrote:
 > Step 6 of micro-refactoring the set_loop():
 >         Use structs to avoid transferring a large number of parameters
 >         in set_loop_configure() and set_loop_info()
 >
 > function                                             old     new   delta
 > set_loop                                             708     720     +12
> ------------------------------------------------------------------------------ > (add/remove: 0/0 grow/shrink: 1/0 up/down: 12/0)               Total: 12 bytes
 >
> Signed-off-by: Xiaoming Ni <[email protected] <mailto:[email protected]>>
 > ---
 >  libbb/loop.c | 54 +++++++++++++++++++++++++++++-----------------------
 >  1 file changed, 30 insertions(+), 24 deletions(-)
 >
...
 > -        */
 > -       loopinfo.lo_flags = (flags & ~BB_LO_FLAGS_READ_ONLY);
 > -       rc = ioctl(lfd, BB_LOOP_SET_STATUS, &loopinfo);
 > -       if (rc != 0 && (loopinfo.lo_flags & BB_LO_FLAGS_AUTOCLEAR)) {
 > +       rc = ioctl(lfd, BB_LOOP_SET_STATUS, loopinfo);
 > +       if (rc != 0 && (loopinfo->lo_flags & BB_LO_FLAGS_AUTOCLEAR)) {
 > +               memcpy(&loopinfo2, loopinfo, sizeof(*loopinfo));

Just use `loopinfo2 = loopinfo;`
Tested on my PC, there was no difference in code size between your modified scheme and my current scheme.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes


Also, it is unclear why there is the need to clone the loopinfo buffer.

 >                 /* Old kernel, does not support LO_FLAGS_AUTOCLEAR? */
 >                 /* (this code path is not tested) */
 > -               loopinfo.lo_flags -= BB_LO_FLAGS_AUTOCLEAR;
 > -               rc = ioctl(lfd, BB_LOOP_SET_STATUS, &loopinfo);
 > +               loopinfo2.lo_flags -= BB_LO_FLAGS_AUTOCLEAR;
 > +               rc = ioctl(lfd, BB_LOOP_SET_STATUS, &loopinfo2);
 >         }
 >         if (rc == 0) {
 >                 return lfd;
...

 >
 > +static void init_bb_loop_info(bb_loop_info *loopinfo, const char *file,
> +               unsigned long long offset, unsigned long long sizelimit, unsigned flags)
 > +{
 > +       memset(loopinfo, 0, sizeof(*loopinfo));

Would it reduce code size by doing the initialization like this?

```
        bb_loop_info empty = {0};
        loopinfo = empty;
```

Tested on my PC, there was no difference in code size between your modified scheme and my current scheme.

function                                             old     new   delta
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes

Thanks
Xiaoming Ni
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to