google-code-export / red5

Automatically exported from code.google.com/p/red5
0 stars 0 forks source link

Client still comes with error prone hashValue() Method #467

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
current hashValue() code is:

[code]
    @Override
    public int hashCode() {
        if (StringUtils.isNumeric(id)) {
            return Integer.valueOf(id);
        } else {
            return id.hashCode();
        }
    }
[/code]

StringUtils.isNumeric does not guarantee that Integer.valueOf() works, since in 
case of high numeric values a NumberFormatException will be thrown nevertheless.

Apart of that i doubt that testing on numeric plus converting into integer will 
be less complex than the default String hashValue().

Suggestion is to simply always use the String default hashValue() if there is 
no benchmark showing that it is grossly inefficient.

Original issue reported on code.google.com by S.No...@gmail.com on 2 Dec 2013 at 7:01

GoogleCodeExporter commented 9 years ago
correction, the method is hashCode() as shown in the code snippet.

A short test confirmed that the default hashCode() in String outperforms the 
current override by orders of magnitude. (test run over random Strings/Numeric 
Strings with 1000 calls to the hashCode calculation, the default method even 
outperformed a djb hash algorithm i used as reference value)

Original comment by S.No...@gmail.com on 2 Dec 2013 at 7:43

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r4738.

Original comment by mondain on 5 Dec 2013 at 12:15

GoogleCodeExporter commented 9 years ago

Original comment by mondain on 5 Dec 2013 at 12:16