worryg0d commented on code in PR #1773:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1773#discussion_r1766663620


##########
crc.go:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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
+ *
+ *     http://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 gocql
+
+import "hash/crc32"
+
+var (
+       // Initial CRC32 bytes: 0xFA, 0x2D, 0x55, 0xCA
+       initialCRC32Bytes = []byte{0xfa, 0x2d, 0x55, 0xca}
+)
+
+// ChecksumIEEE calculates the CRC32 checksum of the given byte slice.
+func ChecksumIEEE(b []byte) uint32 {
+       crc := crc32.NewIEEE()

Review Comment:
   As far as I see each instance of `crc32.digest` created by `crc32.NewIEEE` 
has a pointer to the global `crc32.IEEETable` table, so it doesn't allocate a 
new table on each func call.
   
   ```go
   // New creates a new [hash.Hash32] computing the CRC-32 checksum using the
   // polynomial represented by the [Table]. Its Sum method will lay the
   // value out in big-endian byte order. The returned Hash32 also
   // implements [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to
   // marshal and unmarshal the internal state of the hash.
   func New(tab *Table) hash.Hash32 {
        if tab == IEEETable {
                ieeeOnce.Do(ieeeInit)
        }
        return &digest{0, tab}
   }
   
   // NewIEEE creates a new [hash.Hash32] computing the CRC-32 checksum using
   // the [IEEE] polynomial. Its Sum method will lay the value out in
   // big-endian byte order. The returned Hash32 also implements
   // [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to marshal
   // and unmarshal the internal state of the hash.
   func NewIEEE() hash.Hash32 { return New(IEEETable) }
   ```
   
   ```go
   // IEEETable is the table for the [IEEE] polynomial.
   var IEEETable = simpleMakeTable(IEEE)
   ```



-- 
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]


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

Reply via email to