From 518eb410fe77743ea75be26e12c59a8c78c4717b Mon Sep 17 00:00:00 2001 From: jkmcl Date: Mon, 27 Jun 2022 03:13:58 +0800 Subject: [PATCH] Avoid unnecessary use of Instant.toEpochMilli Avoid unnecessary use of Instant.toEpochMilli by using Instant.compareTo to compare Instants direclty --- .../hc/client5/http/cookie/CookiePriorityComparator.java | 2 +- .../apache/hc/client5/http/impl/cookie/BasicClientCookie.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookiePriorityComparator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookiePriorityComparator.java index 2a8078365..5c95d99ee 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookiePriorityComparator.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/cookie/CookiePriorityComparator.java @@ -59,7 +59,7 @@ public class CookiePriorityComparator implements Comparator { final Instant d1 = c1.getCreationInstant(); final Instant d2 = c2.getCreationInstant(); if (d1 != null && d2 != null) { - return (int) (d1.toEpochMilli() - d2.toEpochMilli()); + return d1.compareTo(d2); } } return result; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java index 18116da99..004df60a2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicClientCookie.java @@ -269,7 +269,7 @@ public final class BasicClientCookie implements SetCookie, Cloneable, Serializab public boolean isExpired(final Date date) { Args.notNull(date, "Date"); return (cookieExpiryDate != null - && cookieExpiryDate.toEpochMilli() <= DateUtils.toInstant(date).toEpochMilli()); + && cookieExpiryDate.compareTo(DateUtils.toInstant(date)) <= 0); } /** @@ -282,7 +282,7 @@ public final class BasicClientCookie implements SetCookie, Cloneable, Serializab public boolean isExpired(final Instant instant) { Args.notNull(instant, "Instant"); return (cookieExpiryDate != null - && cookieExpiryDate.toEpochMilli() <= instant.toEpochMilli()); + && cookieExpiryDate.compareTo(instant) <= 0); } /**