Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9383#discussion_r43567875
  
    --- Diff: 
core/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java ---
    @@ -860,45 +844,48 @@ void growAndRehash() {
           resizeStartTime = System.nanoTime();
         }
         // Store references to the old data structures to be used when we 
re-hash
    -    final LongArray oldLongArray = longArray;
    -    final BitSet oldBitSet = bitset;
    -    final int oldCapacity = (int) oldBitSet.capacity();
    -
    -    // Allocate the new data structures
    -    try {
    -      allocate(Math.min(growthStrategy.nextCapacity(oldCapacity), 
MAX_CAPACITY));
    -    } catch (OutOfMemoryError oom) {
    -      longArray = oldLongArray;
    -      bitset = oldBitSet;
    -      throw oom;
    -    }
    +    final long[] oldLongArray = longArray;
    +    allocate(Math.min(growthStrategy.nextCapacity(longArray.length / 2), 
MAX_CAPACITY));
     
         // Re-mask (we don't recompute the hashcode because we stored all 32 
bits of it)
    -    for (int pos = oldBitSet.nextSetBit(0); pos >= 0; pos = 
oldBitSet.nextSetBit(pos + 1)) {
    -      final long keyPointer = oldLongArray.get(pos * 2);
    -      final int hashcode = (int) oldLongArray.get(pos * 2 + 1);
    +    for (int pos = 0; pos < oldLongArray.length; pos += 2) {
    +      final long keyPointer = oldLongArray[pos];
    +      final int hashcode = (int) oldLongArray[pos + 1];
           int newPos = hashcode & mask;
           int step = 1;
    -      boolean keepGoing = true;
    -
    -      // No need to check for equality here when we insert so this has one 
less if branch than
    -      // the similar code path in addWithoutResize.
    -      while (keepGoing) {
    -        if (!bitset.isSet(newPos)) {
    -          bitset.set(newPos);
    -          longArray.set(newPos * 2, keyPointer);
    -          longArray.set(newPos * 2 + 1, hashcode);
    -          keepGoing = false;
    -        } else {
    -          newPos = (newPos + step) & mask;
    -          step++;
    -        }
    +      while (longArray[newPos * 2] != 0) {
    +        newPos = (newPos + step) & mask;
    +        step++;
           }
    +      longArray[newPos * 2] = keyPointer;
    +      longArray[newPos * 2 + 1] = hashcode;
         }
    -    releaseMemory(oldLongArray.memoryBlock().size());
    +
    +    releaseMemory(oldLongArray.length * 8L);
     
         if (enablePerfMetrics) {
           timeSpentResizingNs += System.nanoTime() - resizeStartTime;
         }
       }
    +
    +  /**
    +   * Return the compacted long array.
    +   */
    +  public long[] getCompactArray() {
    --- End diff --
    
    Is it needed to add comment for it?


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to