Roiocam commented on code in PR #1304:
URL: https://github.com/apache/pekko/pull/1304#discussion_r1627425402


##########
cluster-sharding-typed/src/main/scala/org/apache/pekko/cluster/sharding/typed/internal/ClusterShardingImpl.scala:
##########
@@ -173,10 +174,16 @@ import pekko.util.JavaDurationConverters._
       allocationStrategy: Option[ShardAllocationStrategy]): ActorRef[E] = {
 
     val extractorAdapter = new ExtractorAdapter(extractor)
-    val extractEntityId: ShardRegion.ExtractEntityId = {
-      // TODO is it possible to avoid the double evaluation of entityId
-      case message if extractorAdapter.entityId(message) != null =>
-        (extractorAdapter.entityId(message), 
extractorAdapter.unwrapMessage(message))
+    // !!!important is only applicable if you know that isDefinedAt(x) is 
always called before apply(x) (with the same x)
+    val extractEntityId: ShardRegion.ExtractEntityId = new 
AbstractPartialFunction[Any, (String, Any)] {
+      var cache: String = _
+
+      override def isDefinedAt(msg: Any): Boolean = {
+        cache = extractorAdapter.entityId(msg)
+        cache != null
+      }
+
+      override def apply(x: Any): (DataCenter, Any) = (cache, 
extractorAdapter.unwrapMessage(x))

Review Comment:
   Yep, Looks like it was a mistake.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to