Skip to content

Commit

Permalink
Stop super-sourcing System.nanoTime usages as the API was available s…
Browse files Browse the repository at this point in the history
…ince 2021.

RELNOTES=n/a
PiperOrigin-RevId: 534596151
  • Loading branch information
gkdn authored and Google Java Core Libraries committed May 23, 2023
1 parent 7c473d8 commit 9407ed6
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 24 deletions.
6 changes: 0 additions & 6 deletions android/guava/src/com/google/common/base/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ final class Platform {

private Platform() {}

/** Calls {@link System#nanoTime()}. */
@SuppressWarnings("GoodTime") // reading system time without TimeSource
static long systemNanoTime() {
return System.nanoTime();
}

static CharMatcher precomputeCharMatcher(CharMatcher matcher) {
return matcher.precomputedInternal();
}
Expand Down
3 changes: 2 additions & 1 deletion android/guava/src/com/google/common/base/Suppliers.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static class ExpiringMemoizingSupplier<T extends @Nullable Object>

@Override
@ParametricNullness
@SuppressWarnings("GoodTime") // reading system time without TimeSource
public T get() {
// Another variant of Double Checked Locking.
//
Expand All @@ -253,7 +254,7 @@ public T get() {
// the extra memory consumption and indirection are more
// expensive than the extra volatile reads.
long nanos = expirationNanos;
long now = Platform.systemNanoTime();
long now = System.nanoTime();
if (nanos == 0 || now - nanos >= 0) {
synchronized (this) {
if (nanos == expirationNanos) { // recheck for lost race
Expand Down
3 changes: 2 additions & 1 deletion android/guava/src/com/google/common/base/Ticker.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public static Ticker systemTicker() {
private static final Ticker SYSTEM_TICKER =
new Ticker() {
@Override
@SuppressWarnings("GoodTime") // reading system time without TimeSource
public long read() {
return Platform.systemNanoTime();
return System.nanoTime();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static jsinterop.annotations.JsPackage.GLOBAL;

import java.util.concurrent.TimeUnit;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -33,13 +32,6 @@ static CharMatcher precomputeCharMatcher(CharMatcher matcher) {
return matcher;
}

@SuppressWarnings("GoodTime") // reading system time without TimeSource
static long systemNanoTime() {
// System.nanoTime() is not available in GWT, so we get milliseconds
// and convert to nanos.
return TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
}

static <T extends Enum<T>> Optional<T> getEnumIfPresent(Class<T> enumClass, String value) {
try {
return Optional.of(Enum.valueOf(enumClass, value));
Expand Down
6 changes: 0 additions & 6 deletions guava/src/com/google/common/base/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ final class Platform {

private Platform() {}

/** Calls {@link System#nanoTime()}. */
@SuppressWarnings("GoodTime") // reading system time without TimeSource
static long systemNanoTime() {
return System.nanoTime();
}

static CharMatcher precomputeCharMatcher(CharMatcher matcher) {
return matcher.precomputedInternal();
}
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Suppliers.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static class ExpiringMemoizingSupplier<T extends @Nullable Object>

@Override
@ParametricNullness
@SuppressWarnings("GoodTime") // reading system time without TimeSource
public T get() {
// Another variant of Double Checked Locking.
//
Expand All @@ -253,7 +254,7 @@ public T get() {
// the extra memory consumption and indirection are more
// expensive than the extra volatile reads.
long nanos = expirationNanos;
long now = Platform.systemNanoTime();
long now = System.nanoTime();
if (nanos == 0 || now - nanos >= 0) {
synchronized (this) {
if (nanos == expirationNanos) { // recheck for lost race
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Ticker.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public static Ticker systemTicker() {
private static final Ticker SYSTEM_TICKER =
new Ticker() {
@Override
@SuppressWarnings("GoodTime") // reading system time without TimeSource
public long read() {
return Platform.systemNanoTime();
return System.nanoTime();
}
};
}

0 comments on commit 9407ed6

Please sign in to comment.