m1a2st commented on code in PR #19867:
URL: https://github.com/apache/kafka/pull/19867#discussion_r2120977982


##########
core/src/main/scala/kafka/server/ConfigHelper.scala:
##########
@@ -87,18 +103,26 @@ class ConfigHelper(metadataCache: MetadataCache, config: 
KafkaConfig, configRepo
                       includeDocumentation: Boolean): 
List[DescribeConfigsResponseData.DescribeConfigsResult] = {
     resourceToConfigNames.map { resource =>
 
-      def createResponseConfig(configs: Map[String, Any],
-                               createConfigEntry: (String, Any) => 
DescribeConfigsResponseData.DescribeConfigsResourceResult): 
DescribeConfigsResponseData.DescribeConfigsResult = {
-        val filteredConfigPairs = if (resource.configurationKeys == null || 
resource.configurationKeys.isEmpty)
-          configs.toBuffer
-        else
-          configs.filter { case (configName, _) =>
-            resource.configurationKeys.asScala.contains(configName)
-          }.toBuffer
-
-        val configEntries = filteredConfigPairs.map { case (name, value) => 
createConfigEntry(name, value) }
-        new 
DescribeConfigsResponseData.DescribeConfigsResult().setErrorCode(Errors.NONE.code)
-          .setConfigs(configEntries.asJava)
+      def createResponseConfig(configs: JMap[String, _ <: Object],
+                               createConfigEntry: (String, Object) => 
DescribeConfigsResponseData.DescribeConfigsResourceResult): 
DescribeConfigsResponseData.DescribeConfigsResult = {
+        val keySet: HashSet[String] =
+          if (resource.configurationKeys == null || 
resource.configurationKeys.isEmpty) null
+          else new HashSet[String](resource.configurationKeys)
+
+        val configEntries: 
JList[DescribeConfigsResponseData.DescribeConfigsResourceResult] = {
+          val baseStream = configs.entrySet().stream()
+          val filtered = if (keySet == null) baseStream
+          else baseStream.filter(entry => keySet.contains(entry.getKey))

Review Comment:
   I think we can avoid using null checks to distinguish between different 
filters.



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to