fix(web): replace .map() with .forEach() in formalizePoliciesList - #7149
fix(web): replace .map() with .forEach() in formalizePoliciesList#7149vikash7485 wants to merge 3 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 |
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.