GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MapConverter: avoid HashMap re-hashing. · zhoupan/objectbox-java@0cf652a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox/converter
    • FlexMapConverter.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objectbox-java/src/main/java/io/objectbox/converter/FlexMapConverter.java‎

Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/converter/FlexMapConverter.java
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ private Map<Object, Object> buildMap(FlexBuffers.Map map) {
164164
int entryCount = map.size();
165165
FlexBuffers.KeyVector keys = map.keys();
166166
FlexBuffers.Vector values = map.values();
167-
Map<Object, Object> resultMap = new HashMap<>(entryCount);
167+
// Note: avoid HashMap re-hashing by choosing large enough initial capacity.
168+
// From docs: If the initial capacity is greater than the maximum number of entries divided by the load factor,
169+
// no rehash operations will ever occur.
170+
// So set initial capacity based on default load factor 0.75 accordingly.
171+
Map<Object, Object> resultMap = new HashMap<>((int) (entryCount / 0.75 + 1));
168172
for (int i = 0; i < entryCount; i++) {
169173
String rawKey = keys.get(i).toString();
170174
Object key = convertToKey(rawKey);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.