Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pdata] Add Append and EnsureCapacity methods to primitive slices #6060

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented Sep 13, 2022

Follow-up PR from #5971:

No way of increasing the capacity or length. We can discuss about that API.

Given that we have SetAt interface not Append..., I think it makes sense to have SetLen. But I'm open to other suggestions

Fixes #6063

cc @bogdandrutu

@dmitryax dmitryax requested review from a team and bogdandrutu September 13, 2022 16:57
@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Base: 91.58% // Head: 91.60% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (f098fc3) compared to base (4cf5f82).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6060      +/-   ##
==========================================
+ Coverage   91.58%   91.60%   +0.01%     
==========================================
  Files         217      217              
  Lines       13424    13454      +30     
==========================================
+ Hits        12295    12325      +30     
  Misses        906      906              
  Partials      223      223              
Impacted Files Coverage Δ
pdata/pcommon/generated_primitive_slice.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@bogdandrutu
Copy link
Member

Given that we have SetAt interface not Append..., I think it makes sense to have SetLen. But I'm open to other suggestions

Confused about why not offering an Append(vals ...int64) is not a valid solution as well?

Some other question:

  1. Should we also offer EnsureCapacity?

@dmitryax
Copy link
Member Author

dmitryax commented Sep 13, 2022

@bogdandrutu My reasoning for SetLen is coming from the usage. Usually we know length in advance and just set/update existing elements not appending anything.

Maybe we shouldn't rely on usage and think of the slices in more abstracted way. In that case Append and EnsureCapacity probably is better, since it provides more flexibility going forward. The only downside is that there is no way to shrink the slice without extra allocation. Not sure if it's really feasible use case

@bogdandrutu
Copy link
Member

I think an Append and EnsureCapacity make total sense and moves this so be similar with other slices. In addition we can also have SetLen but want tot understand if it does allocation if not enough space or crash (for example reslicing a slice crash if not enough capacity). I think SetLen can wait until we see more use-cases, what do you think?

@dmitryax
Copy link
Member Author

I think SetLen can wait until we see more use-cases, what do you think?

Ok sounds good. let's do that

@dmitryax dmitryax changed the title [pdata] Add SetLen method to primitive slices [pdata] Add Append and EnsureCapacity methods to primitive slices Sep 14, 2022
@dmitryax
Copy link
Member Author

@bogdandrutu , updated

@bogdandrutu
Copy link
Member

Need a rebase

@dmitryax
Copy link
Member Author

Rebased

@bogdandrutu bogdandrutu merged commit 958ace5 into open-telemetry:main Sep 16, 2022
@dmitryax dmitryax deleted the add-primitive-type-set-len branch September 16, 2022 00:24
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.

Provide a way of increasing the capacity and/or length for the slice of primitives
2 participants