abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r555837 - /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java
Date Fri, 13 Jul 2007 02:22:47 GMT
Author: jmsnell
Date: Thu Jul 12 19:22:46 2007
New Revision: 555837

URL: http://svn.apache.org/viewvc?view=rev&rev=555837
Log:
No need to create a new MessageDigest instance for every instance

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java?view=diff&rev=555837&r1=555836&r2=555837
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java
Thu Jul 12 19:22:46 2007
@@ -26,15 +26,21 @@
 public class SimpleCacheKey implements CacheKey {
 
   private static final long serialVersionUID = 8757289485580165536L;
-  private byte[] key = null;
+  private static MessageDigest md;
   
-  private MessageDigest md = null;
+  private final byte[] key;
   
   public SimpleCacheKey(String uri) {
-    try {
-      md = MessageDigest.getInstance("md5");
-      key = md.digest(uri.getBytes());
-    } catch (Exception e) {}
+    key = getMessageDigest().digest(uri.getBytes());
+  }
+  
+  private static MessageDigest getMessageDigest() {
+    if (md == null) {
+      try {
+        md = MessageDigest.getInstance("md5");
+      } catch (Exception e) {}
+    }
+    return md;
   }
   
   public byte[] getKey() {
@@ -49,7 +55,7 @@
   
   @Override
   public boolean equals(Object obj) {
-    return (obj instanceof CacheKey) ? isMatch((CacheKey)obj) : false;
+    return obj instanceof CacheKey ? isMatch((CacheKey)obj) : false;
   }
   
   @Override



Mime
View raw message