Skip to content

chore(array): optmize array_splice#4088

Open
cnjhb wants to merge 1 commit intoawesomeWM:masterfrom
cnjhb:array
Open

chore(array): optmize array_splice#4088
cnjhb wants to merge 1 commit intoawesomeWM:masterfrom
cnjhb:array

Conversation

@cnjhb
Copy link
Copy Markdown
Contributor

@cnjhb cnjhb commented Mar 16, 2026

This might reduce the overhead of some memcpy calls.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (94d38e6) to head (4567b8c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4088      +/-   ##
==========================================
+ Coverage   90.45%   90.46%   +0.01%     
==========================================
  Files         941      941              
  Lines       60385    60386       +1     
  Branches     1145     1145              
==========================================
+ Hits        54621    54631      +10     
+ Misses       5254     5248       -6     
+ Partials      510      507       -3     

see 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread common/array.h
pfx##_array_splice(pfx##_array_t *arr, int pos, int len, \
type_t items[], int count) \
{ \
assert (pos >= 0 && len >= 0 && count >= 0); \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i wonder should it be moved here to just change count from >= to > 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, passing 0 is indeed a valid operation.
array_take is what passes 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Passing 0 to count means that no elements are inserted into the array.
Just like with array_take, if you only need to remove some elements from the array, you can pass 0 to count.

@cnjhb
Copy link
Copy Markdown
Contributor Author

cnjhb commented Mar 19, 2026

This optimization is actually quite useful;
every array_remove and array_take call can benefit from it.

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