Skip to content

Small improvements, part 2#65

Merged
JavaSaBr merged 3 commits into
developfrom
update-api-part-2
May 13, 2026
Merged

Small improvements, part 2#65
JavaSaBr merged 3 commits into
developfrom
update-api-part-2

Conversation

@JavaSaBr
Copy link
Copy Markdown
Owner

@JavaSaBr JavaSaBr commented May 13, 2026

Changes Summary

1. New Array API: tryTrimTo(int)

  • Added UnsafeMutableArray.tryTrimTo(int internalStorageSize) method to safely resize internal storage
  • Implemented in AbstractMutableArray with validation logic:
    • Returns unchanged if requested size exceeds current capacity
    • Returns unchanged if requested size is less than current element count
    • Performs trimming for valid requests
  • Includes complete javadoc with @since 10.0.alpha14 tag

2. Collection Optimization Pattern

Applied early-exit isEmpty() checks across dictionary implementations to avoid unnecessary allocations and iterations:

  • AbstractHashBasedIntToRefDictionary: 7 methods optimized (keys, values, iterator)
  • AbstractHashBasedLongToRefDictionary: 7 methods optimized
  • AbstractHashBasedRefToRefDictionary: 7 methods optimized

Methods optimized include:

  • iterator() — returns empty iterator immediately
  • keys() (all overloads) — returns empty arrays/containers
  • values() (all overloads) — returns empty arrays/containers

3. Documentation

  • Added comprehensive javadoc to tryTrimTo() method
  • Updated .github/copilot-instructions.md with "Collections optimization pattern" section

Testing & Validation

  • Module build: ./gradlew :rlib-collections:build
  • Full build verification: ./gradlew clean build (recommended before merge)

@JavaSaBr JavaSaBr self-assigned this May 13, 2026
Copilot AI review requested due to automatic review settings May 13, 2026 16:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Bumps the version to 10.0.alpha14 and applies two collection-level improvements: a new tryTrimTo(int) API on UnsafeMutableArray for safe storage shrinking, and pervasive early-exit isEmpty() short-circuits across the three hash-based dictionary implementations to avoid unnecessary allocations and iterations. Also adds a new .github/skills/generate-branch-summary.md skill doc and a "Collections optimization pattern" section to the Copilot instructions.

Changes:

  • Add UnsafeMutableArray.tryTrimTo(int) and implement it in AbstractMutableArray.
  • Add isEmpty() fast paths to iterator(), keys(...) and values(...) overloads in the Int/Long/Ref hash dictionaries.
  • Bump rootProject.version and README example version from 10.0.alpha1310.0.alpha14; add Copilot/skill documentation.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
rlib-collections/src/main/java/javasabr/rlib/collections/array/UnsafeMutableArray.java Adds new tryTrimTo(int) interface method with javadoc.
rlib-collections/src/main/java/javasabr/rlib/collections/array/impl/AbstractMutableArray.java Implements tryTrimTo with capacity/size validation.
rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/impl/AbstractHashBasedIntToRefDictionary.java Adds early-exit isEmpty() checks in iterator/keys/values overloads.
rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/impl/AbstractHashBasedLongToRefDictionary.java Same isEmpty short-circuits for the long-keyed variant.
rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/impl/AbstractHashBasedRefToRefDictionary.java Same isEmpty short-circuits for the ref-keyed variant.
build.gradle Version bump to 10.0.alpha14.
README.md Updates the example rlibVersion to 10.0.alpha14.
.github/copilot-instructions.md Documents the new collections optimization pattern.
.github/skills/generate-branch-summary.md New skill describing how to generate a branch summary.

@github-actions
Copy link
Copy Markdown

Overall Project 54.4% -0.2% 🍏
Files changed 66.67% 🍏

File Coverage
AbstractHashBasedRefToRefDictionary.java 94.67% -2.17% 🍏
AbstractHashBasedLongToRefDictionary.java 89.39% -4.06% 🍏
AbstractHashBasedIntToRefDictionary.java 89.34% -4.08% 🍏
AbstractMutableArray.java 79.02% -5.59%

@github-actions
Copy link
Copy Markdown

Overall Project 54.36% -0.2% 🍏
Files changed 66.67% 🍏

File Coverage
AbstractHashBasedRefToRefDictionary.java 94.67% -2.17% 🍏
AbstractHashBasedLongToRefDictionary.java 89.39% -4.06% 🍏
AbstractHashBasedIntToRefDictionary.java 89.34% -4.08% 🍏
AbstractMutableArray.java 79.02% -5.59%

@JavaSaBr JavaSaBr merged commit 4e6b556 into develop May 13, 2026
6 checks passed
@JavaSaBr JavaSaBr deleted the update-api-part-2 branch May 13, 2026 16:47
@github-actions
Copy link
Copy Markdown

Overall Project 54.38% -0.2% 🍏
Files changed 66.67% 🍏

File Coverage
AbstractHashBasedRefToRefDictionary.java 94.67% -2.17% 🍏
AbstractHashBasedLongToRefDictionary.java 89.39% -4.06% 🍏
AbstractHashBasedIntToRefDictionary.java 89.34% -4.08% 🍏
AbstractMutableArray.java 79.02% -5.59%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants