Skip to content

String search operations needlessly allocate #45393

@jakobnissen

Description

@jakobnissen

For example, findfirst("abc", "ab") eventually ends up calling:

function _searchindex(s::String, t::String, i::Integer)
    # Check for fast case of a single byte
    lastindex(t) == 1 && return something(findnext(isequal(t[1]), s, i), 0)
    _searchindex(unsafe_wrap(Vector{UInt8},s), unsafe_wrap(Vector{UInt8},t), i)
end

The unsafe_wrap allocates, which slows down string search.
However, when I tried replacing the unsafe_wrap(Vector{UInt8}, ::String) with codeunits(::String), Julia failed to bootstrap.

There are a number of similar unsafe_wrap calls in the same file.

It would be nice to remove this allocation, somehow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions