Hi,
thanks for your feedback.
I think it would be more readable here, if you would use if ... else ... .
To me a ternary operator is more readable, if there is one value to compute. Also it enhances
readability over the whole code, if I use less lines as possible, in other words, I hate to scrol
Hi,
thank you for taking time to read my proposal. Is this a matter of some
OpenJDK coding conventions? I myself never use ternary operator and always
use if with braces. My experience is that it improves code readability. If
I have to apply one of proposed changes I would choose first or third.
Hi,
I more would like:
2199 return (s instanceof String)
2200 ? indexOf((String) s) >= 0;
2201 : indexOf(value, 0, value.length, s, 0, s.length(), 0) >=
0;
or:
2199 return (s instanceof String
2200 ? indexOf((String) s)
2201
Hello all,
encouraged by your responses I did a simple implementation and performed
some JMH experiments. Details below.
Webrev [1] contains my changes. I deliberately wanted to do minimal code
changes. The gist of it is implementing indexOf that works on CharSequence
instead of String's internal
There are other places which accept CharSequence and iterate over it
not caring about possible concurrent modification (the only sane way
IMHO). Examples are String.contentEquals and String.join that uses
StringJoiner which iterates its argument char by char.
It looks like contains is the exceptio
>
> If CharSequence is mutable and thread-safe, I would expect toString()
> implementation to provide the atomic snapshot (e.g. do the
> synchronization). Therefore, I find Sherman's argument interesting.
That's my point about "it ought to be up to the caller" -- they're in a
position to make thi
If CharSequence is mutable and thread-safe, I would expect toString()
implementation to provide the atomic snapshot (e.g. do the
synchronization). Therefore, I find Sherman's argument interesting.
On the other hand, we don't seem to be having any details/requirements
for contains(CharSequence) w.r
Yes, but that ought to be for the caller to decide. Also, although the
resulting String is immutable, toString() itself may observe mutation.
On Fri, Mar 20, 2015 at 11:40 AM, Xueming Shen
wrote:
> On 03/20/2015 02:34 AM, Tomasz Kowalczewski wrote:
>
>> Hello!
>>
>> Current implementation of St
On 03/20/2015 02:34 AM, Tomasz Kowalczewski wrote:
Hello!
Current implementation of String.contains that accepts CharSequence calls
toString on it and passes resulting string to indexOf(String). This IMO
defeats the purpose of using CharSequences (that is to have a mutable
character buffer and n
I agree. Adding a new method that doesn't toString the CS would be
desirable. In these special cases, it's perfectly fine if there's no
string intrinsic that kicks in (and thus the actual operation is a bit
slower) -- the goal is to avoid the allocation.
On Fri, Mar 20, 2015 at 8:41 AM, Tomasz K
It is more about custom implementations of CharSuqence that may be backed
by some exotic matter and calling toString on them to create actual String
goes against purpose of CharSequence in the first place (esp. when passing
it to a method that accepts CharSequence). For JDK user it is easy to avoid
On 03/20/2015 03:28 PM, Aleksey Shipilev wrote:
> I wonder if the change is "only" about specializing
> indexOf(CharSequence) on the Java side to shortcut to indexOf(String)
> and others, like String.contentEquals(CharSequence) already does.
Ah, sorry for the confusion, contains(CharSequence) alre
Hi,
On 03/20/2015 03:19 PM, Tomasz Kowalczewski wrote:
> Thank you, that is the kind of feedback I need!
Claes' feedback is spot on. While the change might help, be prepared
that performance research in the area covered by compiler intrinsics is
hard.
> I have also asked myself this question. Ch
Thank you, that is the kind of feedback I need!
I have also asked myself this question. Changing indexOf to accept
CharSequence is the most intrusive move. Safest way is to just implement
contains in a different way (taking code from indexOf) but adding
indexOf(CharSequence) might provide more val
Hi!
While enabling use of CharSequence would seem desirable, there are
some drawbacks that needs to be kept in mind:
- String.indexOf(String) and friends are typically intrinsified on
String in
ways that might not port over well to other implementations of
CharSequence - there might not even b
15 matches
Mail list logo