Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D51C5200BB3 for ; Wed, 2 Nov 2016 13:19:08 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D3C98160AFB; Wed, 2 Nov 2016 12:19:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 273F2160AEA for ; Wed, 2 Nov 2016 13:19:08 +0100 (CET) Received: (qmail 22072 invoked by uid 500); 2 Nov 2016 12:19:07 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 22057 invoked by uid 99); 2 Nov 2016 12:19:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Nov 2016 12:19:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 83511E07EF; Wed, 2 Nov 2016 12:19:06 +0000 (UTC) From: srowen To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request #15736: [SPARK-18224] [CORE] Optimise PartitionedPairBuff... Content-Type: text/plain Message-Id: <20161102121906.83511E07EF@git1-us-west.apache.org> Date: Wed, 2 Nov 2016 12:19:06 +0000 (UTC) archived-at: Wed, 02 Nov 2016 12:19:09 -0000 Github user srowen commented on a diff in the pull request: https://github.com/apache/spark/pull/15736#discussion_r86128297 --- Diff: core/src/main/scala/org/apache/spark/util/collection/PartitionedPairBuffer.scala --- @@ -74,7 +74,20 @@ private[spark] class PartitionedPairBuffer[K, V](initialCapacity: Int = 64) /** Iterate through the data in a given order. For this class this is not really destructive. */ override def partitionedDestructiveSortedIterator(keyComparator: Option[Comparator[K]]) : Iterator[((Int, K), V)] = { - val comparator = keyComparator.map(partitionKeyComparator).getOrElse(partitionComparator) + val comparator : Comparator[(Int, K)] = + if (keyComparator.isEmpty) { + partitionComparator + } else + new Comparator[(Int, K)] { + override def compare(a: (Int, K), b: (Int, K)): Int = { + val partitionDiff = a._1 - b._1 --- End diff -- There are some indentation problems here and the else clause is missing a brace. I think you can omit the type of `comparator`; no space before the colon in any event. This subtraction can overflow in theory and give the wrong answer, but the existing code does it, so, pass on that. While optimizing, do you want to call keyComparator.get outside the class definition? There's a similar construct in PartitionedAppendOnlyMap that should be changed too. Can this be refactored maybe? Can the method partitionKeyComparator go away? I think the whole WritablePartitionedPairCollection object goes away after this if you care to 'inline' it too in the one refactored instance. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org For additional commands, e-mail: reviews-help@spark.apache.org