[PATCH] unnecessary null check inside of java.lang.Boolean.valueOf(String)

Martin Buchholz martinrb at google.com
Thu Mar 22 17:35:51 UTC 2018


If parseBoolean is worth optimizing (barely, but only because Boolean is
very popular), then let's do the usual ASCII bit-twiddling:

    public static boolean parseBoolean(String s) {
        // return "true".equalsIgnoreCase(s);
        return s != null
            && s.length() == 4
            && (s.charAt(0) | 0x20) == 't'
            && (s.charAt(1) | 0x20) == 'r'
            && (s.charAt(2) | 0x20) == 'u'
            && (s.charAt(3) | 0x20) == 'e';
    }

ModuleBootstrap is not worth changing because any system property is very
unlikely to be set - the null check will trip 99.9999% of the time.


More information about the core-libs-dev mailing list