Skip to content

CodePoints.uncons performance optimization? #154

@jamesdbrock

Description

@jamesdbrock

It seems to me that these lines in Data.String.CodePoints.uncons

cu0 = fromEnum (Unsafe.charAt 0 s)
cu1 = fromEnum (Unsafe.charAt 1 s)

are first slicing the first code unit into a Char string with the JavaScript charAt method

if (i >= 0 && i < s.length) return s.charAt(i);

and then converting the Char string to a CodePoint by the boundedEnumChar instance fromEnum method which calls the Javascript charCodeAt method.

https://github.com/purescript/purescript-enums/blob/170d959644eb99e0025f4ab2e38f5f132fd85fa4/src/Data/Enum.js#L4

We could skip the intermediate string slice of the charAt method and call charCodeAt directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions