From a7d70f4b691918680f5533a4b371a6797cd0c84c Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Mon, 26 Nov 2018 17:16:54 -0800
Subject: [PATCH] ChunkedArray.addRepeat

---
 src/mol-data/util/chunked-array.ts        | 9 +++++++++
 src/mol-geo/geometry/mesh/builder/tube.ts | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/mol-data/util/chunked-array.ts b/src/mol-data/util/chunked-array.ts
index bd4dd1086..f7fa1ed91 100644
--- a/src/mol-data/util/chunked-array.ts
+++ b/src/mol-data/util/chunked-array.ts
@@ -77,6 +77,15 @@ namespace ChunkedArray {
         return array.elementCount++;
     }
 
+    export function addRepeat<T>(array: ChunkedArray<T, 1>, n: number, x: T) {
+        for (let i = 0; i < n; i++) {
+            if (array.currentIndex >= array.currentSize) allocateNext(array);
+            array.currentChunk[array.currentIndex++] = x;
+            array.elementCount++;
+        }
+        return array.elementCount;
+    }
+
     export function addMany<T>(array: ChunkedArray<T, any>, data: ArrayLike<T>) {
         const { elementSize } = array;
         for (let i = 0, _i = data.length; i < _i; i += elementSize) {
diff --git a/src/mol-geo/geometry/mesh/builder/tube.ts b/src/mol-geo/geometry/mesh/builder/tube.ts
index 5eabb36f6..f4d5d78c8 100644
--- a/src/mol-geo/geometry/mesh/builder/tube.ts
+++ b/src/mol-geo/geometry/mesh/builder/tube.ts
@@ -131,5 +131,5 @@ export function addTube(builder: MeshBuilder, controlPoints: ArrayLike<number>,
     }
 
     const addedVertexCount = (linearSegments + 1) * radialSegments + (startCap ? radialSegments + 1 : 0) + (endCap ? radialSegments + 1 : 0)
-    for (let i = 0, il = addedVertexCount; i < il; ++i) ChunkedArray.add(groups, currentGroup)
+    ChunkedArray.addRepeat(groups, addedVertexCount, currentGroup)
 }
\ No newline at end of file
-- 
GitLab