sashapolo commented on code in PR #10045:
URL: https://github.com/apache/ignite/pull/10045#discussion_r883535106


##########
modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java:
##########
@@ -181,6 +203,32 @@ private void growEntries() {
         objs = newObjs;
     }
 
+    /**
+     * Tries to gradually shrink hash table by factor of two when it's cleared.
+     *
+     * @return {@code true} if shrinked the table, {@code false} otherwise.
+     */
+    private boolean shrink() {
+        int newLen = objs.length;
+
+        if (newLen > initCap) {
+            int shrinked = (newLen - 1) / 2;

Review Comment:
   `shirnked` is incorrect, should be `shrank`



##########
modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java:
##########
@@ -181,6 +203,32 @@ private void growEntries() {
         objs = newObjs;
     }
 
+    /**
+     * Tries to gradually shrink hash table by factor of two when it's cleared.
+     *
+     * @return {@code true} if shrinked the table, {@code false} otherwise.
+     */
+    private boolean shrink() {
+        int newLen = objs.length;
+
+        if (newLen > initCap) {
+            int shrinked = (newLen - 1) / 2;

Review Comment:
   why `newLen - 1`?



##########
modules/core/src/main/java/org/apache/ignite/internal/util/GridHandleTable.java:
##########
@@ -181,6 +203,32 @@ private void growEntries() {
         objs = newObjs;
     }
 
+    /**
+     * Tries to gradually shrink hash table by factor of two when it's cleared.
+     *
+     * @return {@code true} if shrinked the table, {@code false} otherwise.
+     */
+    private boolean shrink() {
+        int newLen = objs.length;
+
+        if (newLen > initCap) {
+            int shrinked = (newLen - 1) / 2;

Review Comment:
   I think this code can actually be written a little bit simpler:
   ```
   int newLen = Math.max(objs.length / 2, initCap);
   
   if (newLen >= size && newLen < objs.length) {
       init(newLen);
   
       return true;
   }
   
   return false;
   ```



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