Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fixes for review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Feb 16, 2020
1 parent 0645140 commit 4649732
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mbgl/sprite/sprite_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ std::vector<Immutable<style::Image::Impl>> parseSprite(const std::string& encode
}

assert([&images] {
std::sort(images.begin(), images.end(), [](const auto& a, const auto& b) { return a->id < b->id; });
std::sort(images.begin(), images.end());
return std::unique(images.begin(), images.end()) == images.end();
}());
return images;
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/style/image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ using ImageMap = std::unordered_map<std::string, Immutable<style::Image::Impl>>;
using ImageDependencies = std::unordered_map<std::string, ImageType>;
using ImageRequestPair = std::pair<ImageDependencies, uint64_t>;
using ImageVersionMap = std::unordered_map<std::string, uint32_t>;
inline bool operator<(const Immutable<mbgl::style::Image::Impl>& a, const Immutable<mbgl::style::Image::Impl>& b) {
return a->id < b->id;
}

} // namespace mbgl
9 changes: 4 additions & 5 deletions src/mbgl/style/style_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,12 @@ void Style::Impl::onSourceDescriptionChanged(Source& source) {

void Style::Impl::onSpriteLoaded(std::vector<Immutable<style::Image::Impl>> images_) {
auto newImages = makeMutable<ImageImpls>(*images);
const auto cmp = [](const auto& a, const auto& b) { return a->id < b->id; };
assert(std::is_sorted(newImages->begin(), newImages->end(), cmp));
assert(std::is_sorted(newImages->begin(), newImages->end()));

for (auto it = images_.begin(); it != images_.end();) {
const auto& image = *it;
auto first = std::lower_bound(newImages->begin(), newImages->end(), image, cmp);
auto found = first != newImages->end() && !cmp(image, *first) ? first : newImages->end();
auto first = std::lower_bound(newImages->begin(), newImages->end(), image);
auto found = first != newImages->end() && !(image < *first) ? first : newImages->end();
if (found != newImages->end()) {
*found = std::move(*it);
it = images_.erase(it);
Expand All @@ -358,7 +357,7 @@ void Style::Impl::onSpriteLoaded(std::vector<Immutable<style::Image::Impl>> imag

newImages->insert(
newImages->end(), std::make_move_iterator(images_.begin()), std::make_move_iterator(images_.end()));
std::sort(newImages->begin(), newImages->end(), cmp);
std::sort(newImages->begin(), newImages->end());
images = std::move(newImages);
spriteLoaded = true;
observer->onUpdate(); // For *-pattern properties.
Expand Down

0 comments on commit 4649732

Please sign in to comment.