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

StringBuilder that uses an internal LongArray #790

Open
gavinking opened this issue Oct 29, 2015 · 3 comments
Open

StringBuilder that uses an internal LongArray #790

gavinking opened this issue Oct 29, 2015 · 3 comments
Assignees
Milestone

Comments

@gavinking
Copy link
Member

As per this comment on reddit, there is a usage pattern for StringBuilder that we've never really considered, and that seems to be extremely difficult to optimize given the current implementation.

But if StringBuilder were to store its characters in a Java LongArray, we could optimize the for loop to use by-index access.

The question is whether we could then make StringBuilder.string efficient enough. I think it's likely that we could, with some finesse. If not, then perhaps we just need a separate class (StringBuffer??) that behaves like this. The idea being that it's not meant for "building strings", but for aggregating and reading Characters.

Those really are two separate usage patterns, actually.

@gavinking gavinking added this to the 1.3 milestone Oct 29, 2015
@gavinking gavinking self-assigned this Oct 29, 2015
@jvasileff
Copy link
Member

It seems to me that:

  1. Using StringBuilder to create a string is a much more common use case than non-native character iteration , and
  2. With compiler support, there should be some way to optimize away boxing for iteration without changing the underlying storage. Either the compiled code or some helper class would need access to the builder. Maybe some visibility trick. Or, even just hiding "efficient" iteration methods in the object returned by iterator(), and having the compiler perform a cast to gain access to the methods.

This doesn't address random access, but a growable Character list sounds more ArrayList<Character> than a StringBuilder.

@gavinking
Copy link
Member Author

@jvasileff well the issue is that now that StringBuilder is written in pure Ceylon, it's harder to insert backdoors for the compiler to get at its chars.

@jvasileff
Copy link
Member

The object returned by iterator() could satisfy ceylon.language.impl::CharacterIterator with members hasNext and nextCharacter().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants