eclipse-aspectj / aspectj

Other
303 stars 86 forks source link

Avoid unnecessary Map.containsKey calls. #213

Open turbanoff opened 1 year ago

turbanoff commented 1 year ago

Map.containsKey calls are often unnecessary. Depends on the code, we can:

  1. call get() and then compare result with null. Applicable if we know that Map don't contain null value
  2. use putIfAbsent()/computeIfAbsent() if containsKey() was used before put
  3. use getOrDefault() if we have "fallback" value

    I believe it simplifies code and makes it a bit faster.