News for hackers. Stuff that matters.
Re:FastDoubleParser: Java port of Daniel Lemires fast_double... by kuschku on Monday March 22, 2021 @06:10PM (#26547987)

    index += 1;
    if (index < strlen) {
      ch = str.charAt(index);
    } else {
      ch = 0;
    }
If I was using kotlin, I'd do it even cleaner:

    inline fun String.at(index: Int): Char? =
      if (index >= 0 && index < length) charAt(index)
      else null

    [...]

    index += 1
    ch = str.at(index) ?: 0;
The bytecode is exactly the same, but I’d argue it’s much cleaner
Re:FastDoubleParser: Java port of Daniel Lemires fast_double... by mjcohen on Monday March 22, 2021 @07:51PM (#26549107)
I haven't used kotlin, but where is length defined? Should it be a parameter to the function?
Re:FastDoubleParser: Java port of Daniel Lemires fast_double... by pirocks on Monday March 22, 2021 @09:08PM (#26549712)
The above is an extension function(which is basically a member function of class not written in that class), which has an implicit `this` parameter. In other words `length` is actually `this.length`, just as it would be in a regular method.