Reduce calls to strncmp in print_battery_info.c.
Patch status: needinfo
Patch by Kim Svensson ks6g10
Just some tweaks which reduces the number of calls to strncmp in print_battery_info.c. 1. In the for loop around line 67, added a check on walk, if walk point to the null char '\0' then break, as this prevents it from parsing past the information given by slurp. Before it always ran 1024(buf size). 2. Added a check on each line which checks if the variable have already been set, if so no need to do the strncmp and just jump to next branch. 3. Also changed the last strncmp branch from: if (!BEGINS_WITH(last,"POWER_SUPPLY_ENERGY_FULL") && !BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL")) to if (!BEGINS_WITH(last,"POWER_SUPPLY_ENERGY_FULL=") && !BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL=")) Reason is that it is not mutually exclusive with the line below if (!BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_FULL_DESIGN") && !BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_FULL_DESIGN")) hence full_design = atoi(walk+1); is set twice. If 2 is accepted, 3 have to be accepted as well, else the battery will not show the correct information as the first time full_design is set, it is for the wrong value if one have last_full_capacity enabled.
To apply this patch, use:
curl http://cr.i3wm.org/patch/446/raw.patch | git am