Skip to content

perf: Avoid redundant font map lookups#933

Merged
ngxson merged 2 commits intocrosspoint-reader:masterfrom
znelson:dupe-finds
Feb 18, 2026
Merged

perf: Avoid redundant font map lookups#933
ngxson merged 2 commits intocrosspoint-reader:masterfrom
znelson:dupe-finds

Conversation

@znelson
Copy link
Contributor

@znelson znelson commented Feb 16, 2026

Summary

What is the goal of this PR?

Several methods in GfxRenderer were doing a count() followed by at() on the fonts map, effectively doing the same map lookup unnecessarily. This can be avoided by doing a single find() and reusing the iterator.


AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? NO

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db3e55e and 5277415.

📒 Files selected for processing (1)
  • lib/GfxRenderer/GfxRenderer.cpp
🧰 Additional context used
🧬 Code graph analysis (1)
lib/GfxRenderer/GfxRenderer.cpp (1)
lib/Utf8/Utf8.cpp (2)
  • utf8NextCodepoint (11-31)
  • utf8NextCodepoint (11-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cppcheck
  • GitHub Check: build
🔇 Additional comments (9)
lib/GfxRenderer/GfxRenderer.cpp (9)

76-86: LGTM!

The refactor correctly replaces the count() + at() pattern with a single find() call and iterator reuse, eliminating the redundant map lookup while preserving the original error handling logic.


104-119: LGTM!

Good use of a const reference (const auto& font = fontIt->second) to cache the map value for multiple subsequent accesses within the method.


713-721: LGTM!

Consistent application of the find() pattern with proper null check before accessing the font.


723-737: LGTM!

Efficient pattern: the const reference to the font value avoids repeated iterator dereferencing inside the loop.


739-747: LGTM!

Consistent optimization pattern applied correctly.


749-757: LGTM!

Consistent optimization pattern applied correctly.


759-766: LGTM!

Consistent optimization pattern applied correctly.


775-781: LGTM!

Good use of a const reference for the font value, which is accessed multiple times throughout this method for glyph lookups and font data access.


77-78: Consistent and well-executed performance optimization.

The PR successfully replaces all count() + at() double-lookup patterns with single find() calls across 9 methods. The implementation is consistent:

  • Iterator validity is always checked before dereferencing
  • Const references are used when the font value is accessed multiple times within a method
  • Direct fontIt->second access is used for single-access cases

This halves the number of map lookups in the font access paths, which is beneficial for text rendering performance.


📝 Walkthrough

Walkthrough

Refactors font-map lookups in GfxRenderer.cpp: replaces fontMap.count() + fontMap.at() patterns with a single fontMap.find() and iterator reuse across multiple text-rendering methods, preserving public signatures and behavior.

Changes

Cohort / File(s) Summary
Font-map lookup refactoring
lib/GfxRenderer/GfxRenderer.cpp
Replaced fontMap.count(fontId) == 0 and subsequent fontMap.at(fontId) usages with auto fontIt = fontMap.find(fontId); checks vs fontMap.end() and fontIt->second reuse across getTextWidth, drawText, getSpaceWidth, getTextAdvanceX, getFontAscenderSize, getLineHeight, getTextHeight, drawTextRotated90CW, and related internal font accesses. No API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'perf: Avoid redundant font map lookups' clearly and concisely summarizes the main change: replacing redundant count()+at() calls with a single find() operation for better performance.
Description check ✅ Passed The description clearly explains the problem (redundant map lookups via count() followed by at()), the solution (using find() and reusing the iterator), and aligns perfectly with the changeset.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@znelson znelson marked this pull request as ready for review February 16, 2026 17:22
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/GfxRenderer/GfxRenderer.cpp (1)

749-757: ⚠️ Potential issue | 🟡 Minor

Incomplete refactor: fontMap.at() still used after find().

Line 756 still uses fontMap.at(fontId) instead of fontIt->second, which defeats the optimization goal by performing a redundant lookup.

Proposed fix
   return fontMap.at(fontId).getData(EpdFontFamily::REGULAR)->advanceY;
+  return fontIt->second.getData(EpdFontFamily::REGULAR)->advanceY;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6f38d4 and db3e55e.

📒 Files selected for processing (1)
  • lib/GfxRenderer/GfxRenderer.cpp
🧰 Additional context used
🧬 Code graph analysis (1)
lib/GfxRenderer/GfxRenderer.cpp (1)
lib/Utf8/Utf8.cpp (2)
  • utf8NextCodepoint (11-31)
  • utf8NextCodepoint (11-11)
🔇 Additional comments (7)
lib/GfxRenderer/GfxRenderer.cpp (7)

77-84: LGTM!

Clean refactor from count() + at() to find() + iterator reuse. The iterator is correctly checked against end() before dereferencing.


104-109: LGTM!

Good use of a const reference (const auto& font = fontIt->second) to cache the map value for multiple subsequent uses.


714-720: LGTM!

Correct refactor pattern applied.


724-734: LGTM!

Good pattern: caches the font reference before the loop to avoid repeated iterator dereferences.


740-746: LGTM!

Correct refactor pattern applied.


760-765: LGTM!

Correct refactor pattern applied.


775-781: LGTM!

Correct refactor with reference caching for the font used throughout the method.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 16, 2026
@ngxson ngxson merged commit 9125a7c into crosspoint-reader:master Feb 18, 2026
6 checks passed
lukestein pushed a commit to lukestein/crosspoint-reader that referenced this pull request Feb 18, 2026
## Summary

**What is the goal of this PR?**

Several methods in GfxRenderer were doing a `count()` followed by `at()`
on the fonts map, effectively doing the same map lookup unnecessarily.
This can be avoided by doing a single `find()` and reusing the iterator.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_
@znelson znelson deleted the dupe-finds branch February 18, 2026 13:55
ariel-lindemann pushed a commit to ariel-lindemann/crosspoint-reader that referenced this pull request Feb 19, 2026
## Summary

**What is the goal of this PR?**

Several methods in GfxRenderer were doing a `count()` followed by `at()`
on the fonts map, effectively doing the same map lookup unnecessarily.
This can be avoided by doing a single `find()` and reusing the iterator.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_
saslv pushed a commit to saslv/crosspoint-reader that referenced this pull request Feb 19, 2026
## Summary

**What is the goal of this PR?**

Several methods in GfxRenderer were doing a `count()` followed by `at()`
on the fonts map, effectively doing the same map lookup unnecessarily.
This can be avoided by doing a single `find()` and reusing the iterator.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_
el pushed a commit to el/crosspoint-reader that referenced this pull request Feb 19, 2026
## Summary

**What is the goal of this PR?**

Several methods in GfxRenderer were doing a `count()` followed by `at()`
on the fonts map, effectively doing the same map lookup unnecessarily.
This can be avoided by doing a single `find()` and reusing the iterator.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_
lukestein pushed a commit to lukestein/crosspoint-reader that referenced this pull request Feb 20, 2026
## Summary

**What is the goal of this PR?**

Several methods in GfxRenderer were doing a `count()` followed by `at()`
on the fonts map, effectively doing the same map lookup unnecessarily.
This can be avoided by doing a single `find()` and reusing the iterator.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_
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