Page MenuHomeFreeBSD

[libc] strstr implementation update to match musl's
ClosedPublic

Authored by devnexen_gmail.com on Apr 5 2019, 11:13 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 22, 1:03 AM
Unknown Object (File)
Sep 17 2024, 7:42 PM
Unknown Object (File)
Sep 3 2024, 8:29 AM
Unknown Object (File)
Aug 21 2024, 7:58 PM
Unknown Object (File)
Aug 21 2024, 7:58 PM
Unknown Object (File)
Aug 21 2024, 7:58 PM
Unknown Object (File)
Aug 21 2024, 7:14 PM
Unknown Object (File)
Aug 16 2024, 10:03 AM
Subscribers

Details

Summary
  • Updated since 2018 in must-libc.
  • Little optimisation in the two-way function avoiding needless redundant condition check.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

For reference,

commit 122d67f846cb0be2c9e1c3880db9eb9545bbe38c
Author: Rich Felker <dalias@aerifal.cx>
Date:   Thu Nov 8 15:00:02 2018 -0500

    optimize two-way strstr and memmem bad character shift
    
    first, the condition (mem && k < p) is redundant, because mem being
    nonzero implies the needle is periodic with period exactly p, in which
    case any byte that appears in the needle must appear in the last p
    bytes of the needle, bounding the shift (k) by p.
    
    second, the whole point of replacing the shift k by mem (=l-p) is to
    prevent shifting by less than mem when discarding the memory on shift,
    in which case linear time could not be guaranteed. but as written, the
    check also replaced shifts greater than mem by mem, reducing the
    benefit of the shift. there is no possible benefit to this reduction of
    the shift; since mem is being cleared, the full shift is valid and
    more optimal. so only replace the shift by mem when it would be less
    than mem.

commit 0239cd0681e889a269fb7691f60e81ef8d081e6b
Author: Rich Felker <dalias@aerifal.cx>
Date:   Fri Nov 2 12:04:41 2018 -0400

    remove commented-out debug printf from strstr
    
    this was leftover from before the initial commit.

commit 8f5a820d147da36bcdbddd201b35d293699dacd8
Author: Rich Felker <dalias@aerifal.cx>
Date:   Fri Nov 2 12:01:37 2018 -0400

    fix spuriously slow check in twoway strstr/memmem cores
    
    mem0 && mem && ... is redundant since mem can only be nonzero when
    mem0 is nonzero.
This revision is now accepted and ready to land.Apr 5 2019, 11:35 PM
This revision was automatically updated to reflect the committed changes.