Skip to content

bytes.Equal shouldn't allocate #4045

Open
@dgryski

Description

@dgryski

TinyGo uses the bytes package from upstream Go.

// Equal reports whether a and b
// are the same length and contain the same bytes.
// A nil argument is equivalent to an empty slice.
func Equal(a, b []byte) bool {
        // Neither cmd/compile nor gccgo allocates for these string conversions.
        return string(a) == string(b)
}

However, the []byte->string conversion does allocate on TinyGo. We should replace calls to bytes.Equal with a call to our own function that doesn't allocate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions