keith-turner commented on code in PR #4748:
URL: https://github.com/apache/accumulo/pull/4748#discussion_r1707995810


##########
core/src/main/java/org/apache/accumulo/core/data/ImmutableByteSequence.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.data;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.apache.accumulo.core.util.ByteBufferUtil;
+
+/**
+ * An immutable implementation of {@link ByteSequence} that copies data in its 
constructor and never
+ * lets its internal byte array escape. This class is final to prevent it from 
being made mutable in
+ * a subclass.
+ *
+ * <p>
+ * This class is package private because direct construction is not expected, 
instead use of methods
+ * like {@link ByteSequence#of(byte[])} is how instances of this should be 
created.
+ * </p>
+ */
+final class ImmutableByteSequence extends ByteSequence {
+
+  private static final long serialVersionUID = 1L;
+
+  // A reference to this must never escape this class.
+  private final byte[] data;
+
+  private int hash = 1;
+  private boolean hashIsOne = false;
+
+  ImmutableByteSequence(ByteSequence data) {
+    if (data.isBackedByArray()) {
+      this.data =
+          Arrays.copyOfRange(data.getBackingArray(), data.offset(), 
data.offset() + data.length());
+    } else {
+      var dataArray = data.toArray();
+      this.data = Arrays.copyOf(dataArray, dataArray.length);
+    }
+  }
+
+  /**
+   * Creates a new sequence. The array is copied into an new internal array.
+   *
+   * @param data byte data
+   */
+  ImmutableByteSequence(byte[] data) {
+    this.data = Arrays.copyOf(data, data.length);

Review Comment:
   updated in 1320c9b



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to