fix(web): replace .map() with .forEach() in formalizePoliciesList - #7149
fix(web): replace .map() with .forEach() in formalizePoliciesList#7149vikash7485 wants to merge 6 commits into
Conversation
.map() was used at 4 locations in formalizePoliciesList purely for side effects (.push() into outer arrays). Each .map() call silently creates and discards an intermediate array of undefined values, wasting memory. Using .forEach() is semantically correct. Related: pipe-cd#6706 Signed-off-by: vikash7485 <vikkiraj073@gmail.com>
c9a4c19 to
8d197e7
Compare
rahulshendre
left a comment
There was a problem hiding this comment.
nice catch @vikash7485
btw what are your thoughts on using map().join() here 👀
✅ Deploy Preview for pipecd-site canceled.
|
|
@rahulshendre I think using I'd be happy to refactor it to a fully declarative |
sounds good, go for it 🙌 the map().join() version reads much cleaner and it drops that slice(0, -1) too |
There was a problem hiding this comment.
Pull request overview
This PR updates the web utility formalizePoliciesList to use .forEach() instead of .map() in four places where iteration is performed purely for side effects (pushing into outer arrays), avoiding unnecessary intermediate array allocations.
Changes:
- Replace
policiesList.map(...)withpoliciesList.forEach(...)when building thepoliciesoutput list. - Replace
resourcesList.map(...)andactionsList.map(...)with.forEach(...)while populatingresourcesandactions. - Replace
labelsMap.map(...)with.forEach(...)when appending label key/value pairs into the resource string.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
What this PR does:
Replace 4 misused
.map()calls with.forEach()informalizePoliciesList(web/src/utils/formalize-policies-list.ts).Why we need it:
.map()was used at 4 locations purely for side effects (.push()into outer arrays). Each.map()call silently creates and discards an intermediate[undefined, undefined, ...]array, wasting memory. Using.forEach()is semantically correct and avoids the unnecessary allocation.Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?:
No. This is a semantic code correctness fix with no behavioral change.