R
Red Orchid
I think that if the methods of 'String' are not
efficient, these exert a very bad influence on
the performance of an application.
Java do not support any String methods with ignoreCase
except 'String.equalsIgnoreCase' and 'String.regionMatches'.
Threrefore, I think that java leads a programmer to
write the codes that are inefficient.
In proof of my thinking, I will show examples bellow.
<example_#1>
String src = ..;
String key = ..;
... = src.toLowerCase().indexOf(key.toLowerCase());
#1 is very inefficient. because #1 converts the entire
of 'src' to lowerCase though there is no need to do so.
That is,
if src = "abcdefghij" and key = "bc", there is need
to convert only "abc" of src to lowerCase.
The codes like the above are found very common in java
application sources.
<example_#2>
'String.regionMatches' do not provide valuable aid for
solving the inefficient of #1.
Because ..
the folowing code is a part of 'String.regionMatches'
Assuming 'src.regionMatches(true, i, key, j, ...)'.
if (ignoreCase) {
...
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
..
Whenver 'regionMatches' is called, 'key' is converted
to upperCase. it is inefficient.
<example_#3>
A programmer can write his method like the follows.
String k = key.toLowerCase();
for (int i = 0; i < src.length(); i++) {
for (int j = 0; j < k.length(); j++) {
char c = Character.toLowerCase(src.charAt(i + j));
if (c != k.charAt(j)) {
....
#3 calls 'String.charAt'. That is, #3 has the overhead
of function call (method call). if his method exists
inside 'String', he can access the field 'value[]' of
'String' and then his method will not have the overhead.
</example_*>
I think that java do not support 'String' methods enough
or properly.
What is your opinion ?
Thanks.
efficient, these exert a very bad influence on
the performance of an application.
Java do not support any String methods with ignoreCase
except 'String.equalsIgnoreCase' and 'String.regionMatches'.
Threrefore, I think that java leads a programmer to
write the codes that are inefficient.
In proof of my thinking, I will show examples bellow.
<example_#1>
String src = ..;
String key = ..;
... = src.toLowerCase().indexOf(key.toLowerCase());
#1 is very inefficient. because #1 converts the entire
of 'src' to lowerCase though there is no need to do so.
That is,
if src = "abcdefghij" and key = "bc", there is need
to convert only "abc" of src to lowerCase.
The codes like the above are found very common in java
application sources.
<example_#2>
'String.regionMatches' do not provide valuable aid for
solving the inefficient of #1.
Because ..
the folowing code is a part of 'String.regionMatches'
Assuming 'src.regionMatches(true, i, key, j, ...)'.
if (ignoreCase) {
...
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
..
Whenver 'regionMatches' is called, 'key' is converted
to upperCase. it is inefficient.
<example_#3>
A programmer can write his method like the follows.
String k = key.toLowerCase();
for (int i = 0; i < src.length(); i++) {
for (int j = 0; j < k.length(); j++) {
char c = Character.toLowerCase(src.charAt(i + j));
if (c != k.charAt(j)) {
....
#3 calls 'String.charAt'. That is, #3 has the overhead
of function call (method call). if his method exists
inside 'String', he can access the field 'value[]' of
'String' and then his method will not have the overhead.
</example_*>
I think that java do not support 'String' methods enough
or properly.
What is your opinion ?
Thanks.