Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop special casing InlineString1 #80

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Jul 12, 2024

I was looking into fixing #15 but realized that the special casing of InlineString1 to only have one byte makes that not work. I would say that the current special casing of InlineString1 creates quite a bit of confusing behavior:

julia> InlineString("") |> typeof
String3

julia> InlineString("a") |> typeof
String1

Why would an empty string take more place than a one-letter string?


julia> String1("")
ERROR: ArgumentError: string too large (0) to convert to String1
Stacktrace:
 [1] stringtoolong(T::Type, n::Int64)
   @ InlineStrings ~/.julia/packages/InlineStrings/xUsry/src/InlineStrings.jl:321
 [2] String1(x::String)
   @ InlineStrings ~/.julia/packages/InlineStrings/xUsry/src/InlineStrings.jl:208
 [3] top-level scope
   @ REPL[4]:1

julia> String3("")
""

Wut?


julia> rstrip(String3("aaa")) |> typeof
String3

julia> rstrip(String1("a")) |> typeof
String3

Why would rstrip make it bigger?


julia> inlinestrings(["a", "b", ""])
ERROR: ArgumentError: string too large (0) to convert to String1
Stacktrace:

This looks like a bug?


There are also casts to InlineString3 that have to be done for many of the operations on InlineString1 which probably makes them slower than storing the two bytes.

There is nothing in the documentation that indicates this type of special behavior.

I'm sure there is some reason for doing this since so much pain seems to have been gone through to do it but I thought I would put up this PR nonetheless.

Fixes #73 Fixes #72

@KristofferC KristofferC force-pushed the kc/inlinestring1 branch 3 times, most recently from 226a2fe to 3864260 Compare July 12, 2024 20:52
@quinnj
Copy link
Member

quinnj commented Jul 12, 2024

Yeah, this is probably fine; the integration tests pass, so it doesn't look like it'd be breaking from that perspective. I say go for it.

I was looking into fixing JuliaStrings#15 but realized that the special casing of `InlineString1` to only have one byte makes that not work. I would say that the current special casing of `InlineString1` creates quite a bit of confusing behavior:

```
julia> InlineString("") |> typeof
String3

julia> InlineString("a") |> typeof
String1
```

Why would an empty string take more place than a one letter string?

```

julia> String1("")
ERROR: ArgumentError: string too large (0) to convert to String1
Stacktrace:
 [1] stringtoolong(T::Type, n::Int64)
   @ InlineStrings ~/.julia/packages/InlineStrings/xUsry/src/InlineStrings.jl:321
 [2] String1(x::String)
   @ InlineStrings ~/.julia/packages/InlineStrings/xUsry/src/InlineStrings.jl:208
 [3] top-level scope
   @ REPL[4]:1

julia> String3("")
""
```

Wut?

There is nothing in the documentation that indicates this type of special behavior.

I'm sure there is some reason for doing this since so much pain seems to have been gone through to do it but I thought I would put up this PR nonetheless.

Fixes JuliaStrings#73
Fixes JuliaStrings#72
@KristofferC KristofferC merged commit 66586a1 into JuliaStrings:main Jul 23, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants