Use `putIfAbsent()` instead of `get()`/`put()` in `PersistentStringIndexer`.

Doesn't affect memory use, just something I noticed while working on the memory footprint. It's inside of a `synchronized` block, so reducing work is helpful.

PiperOrigin-RevId: 625671056
Change-Id: Id5ee8f9fcc6f3c13bbd060081277d778e333b9ee
diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/PersistentStringIndexer.java b/src/main/java/com/google/devtools/build/lib/actions/cache/PersistentStringIndexer.java
index 58040cf..c3204d9 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/cache/PersistentStringIndexer.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/cache/PersistentStringIndexer.java
@@ -90,14 +90,11 @@
     }
     s = StringCanonicalizer.intern(s);
     synchronized (this) {
-      // First, make sure another thread hasn't just added the entry.
-      i = stringToInt.get(s);
-      if (i != null) {
-        return i;
+      i = stringToInt.size();
+      Integer existing = stringToInt.putIfAbsent(s, i);
+      if (existing != null) {
+        return existing; // Another thread won the race.
       }
-
-      i = intToString.size();
-      stringToInt.put(s, i);
       intToString.put(i, s);
       return i;
     }