Files
codeql/java/ql/src/Performance/InefficientEmptyStringTest.java
2018-08-30 10:48:05 +01:00

18 lines
388 B
Java

// Inefficient version
class InefficientDBClient {
public void connect(String user, String pw) {
if (user.equals("") || "".equals(pw))
throw new RuntimeException();
...
}
}
// More efficient version
class EfficientDBClient {
public void connect(String user, String pw) {
if (user.length() == 0 || (pw != null && pw.length() == 0))
throw new RuntimeException();
...
}
}