Skip to content

Should String substringFrom:to: check indexes? #39

Open
@ltratt

Description

@ltratt

At the moment substringFrom:to: is implemented thus:

    substringFrom: start to: end = (
        ((end <= self length) && (start > 0) && (start <= end))
            ifTrue: [^self primSubstringFrom: start to: end]
            ifFalse: [
                self error: 'Attempting to index string out of its bounds (start: ' + start asString + ' end: ' + end asString + ' length: ' + self length asString + ')' ]
    )

which feels unidiomatic because:

  1. there's no way that primSubStringFrom:to: can not recheck those indexes, since any old Tom, Dick, or Harry can call primSubStringFrom:to: with whatever arguments they want.
  2. other indexing primitives such as Array at: do not have a primAt variant (i.e. the VM is expected to check the indexes).

I was expecting this part of the library to just be substringFrom:to: = primitive -- perhaps we can simplify (and speed up!) this code by doing so?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproves the implementation with something noteworthyhelp wantedPull requests very welcome (usually easier than other issues)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions