-
Notifications
You must be signed in to change notification settings - Fork 201
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
asString and asCharSequenceView for CharLists #224
Comments
I've got a PR in progress but I would like to source some feedback before I go too much further with it. |
The conversion to string sounds more like a helper method for CharCollections. For the view, I'd use charSequenceView(), which makes clear that no copying is performed. |
Yes, but then things like I could special case
Yeah, that sounds good |
Good point, if you can do much better than a method might be a good idea. Maybe you can default it in CharCollection and then have improved overrides. Presently I'm more focused on reviewing the code and #162 , as I want either to complete it (with functions) or at least be sure we won't get into trouble in the future when we complete it (e.g., method calls becoming ambiguous). |
Thoughts on the name of the method? And yeah, I wouldn't mind if this even gets pushed to 8.6.0, not a high priority feature by any means. |
How does |
EDIT: Edited the OP with these new method names |
Just a heads up, I have a branch halfway done implementing this, but IRL work got busy before I could clean it up for submission |
Ok, I have the type I want to expose for unmodifiable view (basically a plain char sequence but also supporting many of the non-mutation methods StringBuilder provides, like I may limit my scope to an unmodifiable view first, and then add in optional mutable views in later PRs |
It may be useful to have
asString
(returns a new String with the elements of the CharCollection as its characters) andasCharSequenceView
(presents a view of theCharList
as aCharSequence
, no copying) inCharList
. PerhapsasString
would make sense inCharCollection
too as there are some ordered non-list collections where it might make sense (SortedSet, LinkedHashSet, etc).CharSequence
is an inherently indexed based api (well, so isString
, but that one will be a copy, not a view), so it only makes sense onCharList
sI'm not sure if
elementsToString
is really a good name.contentsToString
andstringValue
also come to mind.I do like
asCharSequence
though.EDIT: Per discussion on the bug, the names decided on are
asString
andasCharSequenceView
The motivation for this is to:
String
(like if they are already backed by an array, we can just pass that array toString.copyValueOf
instead of a loop copying into another array that is copied again byString
's constructors).CharSequence
view for interfacing with String based APIs without introducing an extra intermediary copy. Also gives an easy way to provide conversions to codepoints (CharSequence
comes with default method APIs for that)The text was updated successfully, but these errors were encountered: