1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #28907 from chacha21:more_autobuffer

More use of AutoBuffer #28907

When possible, AutoBuffer should be faster than std::vector<>, and should not be worse if it requires a heap allocation rather than a stack allocation.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [X] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [X] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Pierre Chatelier
2026-06-16 17:51:37 +02:00
committed by GitHub
parent 3def56d25a
commit 6eb0dc97f5
22 changed files with 70 additions and 66 deletions
@@ -47,8 +47,8 @@ void find_nearest(const Matrix<typename Distance::ElementType>& dataset, typenam
typedef typename Distance::ResultType DistanceType;
int n = nn + skip;
std::vector<int> match(n);
std::vector<DistanceType> dists(n);
cv::AutoBuffer<int> match(n);
cv::AutoBuffer<DistanceType> dists(n);
dists[0] = distance(dataset[0], query, dataset.cols);
match[0] = 0;
@@ -686,8 +686,8 @@ private:
return;
}
std::vector<int> centers(branching);
std::vector<int> labels(indices_length);
cv::AutoBuffer<int> centers(branching);
cv::AutoBuffer<int> labels(indices_length);
int centers_length;
(this->*chooseCenters)(branching, dsindices, indices_length, &centers[0], centers_length);
@@ -99,8 +99,8 @@ float search_with_ground_truth(NNIndex<Distance>& index, const Matrix<typename D
KNNResultSet<DistanceType> resultSet(nn+skipMatches);
SearchParams searchParams(checks);
std::vector<int> indices(nn+skipMatches);
std::vector<DistanceType> dists(nn+skipMatches);
cv::AutoBuffer<int> indices(nn+skipMatches);
cv::AutoBuffer<DistanceType> dists(nn+skipMatches);
int* neighbors = &indices[skipMatches];
int correct = 0;
@@ -490,7 +490,7 @@ inline LshStats LshTable<unsigned char>::getStats() const
!= end; )
if (*iterator < bin_end) {
if (is_new_bin) {
stats.size_histogram_.push_back(std::vector<unsigned int>(3, 0));
stats.size_histogram_.emplace_back(3, 0);
stats.size_histogram_.back()[0] = bin_start;
stats.size_histogram_.back()[1] = bin_end - 1;
is_new_bin = false;