From 8e2ec3c49bf1b6267effd69216daaba62c9622d0 Mon Sep 17 00:00:00 2001 From: Michael Steindorfer Date: Tue, 4 May 2021 16:32:08 +0200 Subject: [PATCH] [Capsule] Make `copyAndSetNode` generic --- Sources/Capsule/_BitmapIndexedMapNode.swift | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Sources/Capsule/_BitmapIndexedMapNode.swift b/Sources/Capsule/_BitmapIndexedMapNode.swift index fd11bf09..5ffe0bdd 100644 --- a/Sources/Capsule/_BitmapIndexedMapNode.swift +++ b/Sources/Capsule/_BitmapIndexedMapNode.swift @@ -97,7 +97,7 @@ final class BitmapIndexedMapNode : MapNode where Key : Hashable { if (!effect.modified) { return self } else { - return copyAndSetCollisionNode(bitpos, subNodeNew) // NOTE difference in callee + return copyAndSetNode(bitpos, subNodeNew) } } else { // regular sub-node @@ -172,7 +172,7 @@ final class BitmapIndexedMapNode : MapNode where Key : Hashable { default: // equivalent to `case 2...` // modify current node (set replacement node) - return copyAndSetCollisionNode(bitpos, subNodeNew) // NOTE difference in callee + return copyAndSetNode(bitpos, subNodeNew) } } else { // regular sub-node @@ -296,18 +296,7 @@ final class BitmapIndexedMapNode : MapNode where Key : Hashable { return BitmapIndexedMapNode(dataMap, nodeMap, dst) } - // TODO rework temporarily duplicated methods for type-safe access - func copyAndSetNode(_ bitpos: Int, _ newNode: BitmapIndexedMapNode) -> BitmapIndexedMapNode { - let idx = self.content.count - 1 - self.nodeIndex(bitpos) - - var dst = self.content - dst[idx] = newNode - - return BitmapIndexedMapNode(dataMap, nodeMap, dst) - } - - // TODO rework temporarily duplicated methods for type-safe access - func copyAndSetCollisionNode(_ bitpos: Int, _ newNode: HashCollisionMapNode) -> BitmapIndexedMapNode { + func copyAndSetNode(_ bitpos: Int, _ newNode: T) -> BitmapIndexedMapNode { let idx = self.content.count - 1 - self.nodeIndex(bitpos) var dst = self.content