Storm-1128 Sort the results of using search in the World Map
Review Request #262 - Created April 13, 2011 and submitted
Jonathan Yap | Reviewers | ||
2.6 | viewer | ||
Storm-1128 | |||
None | viewer-development |
The results of using the World Map search option are sorted.
No major objections.
-
indra/newview/llfloaterworldmap.cpp (Diff revision 1) -
CS: sim_info_vec
-
indra/newview/llfloaterworldmap.cpp (Diff revision 1) -
I'd move the iterator declaration inside the "for" clause to limit its scope.
Posted (April 13, 2011, 2:31 p.m.)
-
indra/newview/llfloaterworldmap.cpp (Diff revision 1) -
Why do you make this a functor rather than a plain normal function? It's not like we have to keep any internal state or something.
-
indra/newview/llfloaterworldmap.cpp (Diff revision 1) -
Wow, long line. Might want to put the arguments on separate lines.
Review request changed
Updated (April 15, 2011, 11:33 a.m.)
-
- added Diff r2
Cleaned up code per some codereview comments.
Posted (April 15, 2011, 3:34 p.m.)
I tried to compile with your change on Linux (g++ 4.4.5)
-
indra/newview/llfloaterworldmap.cpp (Diff revision 2) -
GCC chokes on the "std::vector<std::pair <U64, LLSimInfo*>>", thinking ">>" is the shift/stream operator. Insert a space to distinguish it from the that: std::vector<std::pair <U64, LLSimInfo*> > sim_info_vec(LLWorldMap::getInstance()->getRegionMap().begin(), LLWorldMap::getInstance()->getRegionMap().end());
-
indra/newview/llfloaterworldmap.cpp (Diff revision 2) -
Here, I'm getting indra/newview/llfloaterworldmap.cpp: In member function ‘void LLFloaterWorldMap::updateSims(bool)’: indra/newview/llfloaterworldmap.cpp:1498: error: no matching function for call to ‘sort(__gnu_cxx::__normal_iterator<std::pair<long long unsigned int, LLSimInfo*>*, std::vector<std::pair<long long unsigned int, LLSimInfo*>, std::allocator<std::pair<long long unsigned int, LLSimInfo*> > > >, __gnu_cxx::__normal_iterator<std::pair<long long unsigned int, LLSimInfo*>*, std::vector<std::pair<long long unsigned int, LLSimInfo*>, std::allocator<std::pair<long long unsigned int, LLSimInfo*> > > >, LLFloaterWorldMap::updateSims(bool)::SortRegionNames)’ I'm not sure how to fix that. :-\ I tried an #include <algorithm>, but that didn't make this error go away. (But would probably be a good idea anyway.)
-
indra/newview/llfloaterworldmap.cpp (Diff revision 2) -
Here, too, "> >" instead of ">>".
Review request changed
Updated (April 16, 2011, 6:24 a.m.)
-
- added Diff r3
To fix some issues with gcc made some formatting changes and moved the compare routine back to the top of the code.
Posted (April 16, 2011, 12:37 p.m.)
-
indra/newview/llfloaterworldmap.cpp (Diff revision 3) -
remove trailing whitespace
-
indra/newview/llfloaterworldmap.cpp (Diff revision 3) -
If this has to be outside of LLFloaterWorldMap::updateSims to make GCC happy, we could as well simplify it to ... inline bool sort_region_names(std::pair <U64, LLSimInfo*> const& _left, std::pair <U64, LLSimInfo*> const& _right) { return (LLStringUtil::compareInsensitive(_left.second->getName(),_right.second->getName()) < 0); } ... and then call std::sort in LLFloaterWorldMap::updateSims with ... std::sort(sim_info_vec.begin(), sim_info_vec.end(), &sort_region_names); ... i.e. have a function rather than a functor. I guess the only reason for wrapping the function into a struct would be to workaround the lack of method-local functions in C++. (Compare http://www.flipcode.com/archives/Local_Functions_In_C.shtml . Comments on http://stackoverflow.com/questions/2202731/is-there-support-in-c-stl-for-sorting-objects-by-attribute/2202846#2202846 indicate that functors might sometimes/often perform better, but doesn't explain when or why.) Jonathan Yap said on IRC he prefers the functor (i.e. the variant with the struct) for consistency reasons. (Apparently it's used elsewhere in the code in similar situations.) If someone knows how to call std::sort so that the functor can be method-local, please speak up. (In that case I'd prefer that and thus keep the struct.) Lambda functions (e.g. from BOOST) would be another idea, but let's not go there unless someone comes up with ready-to-use code.
-
indra/newview/llfloaterworldmap.cpp (Diff revision 3) -
Consider replacing the type notation const std::pair <U64, LLSimInfo*>& be the (equivalent!) notation std::pair <U64, LLSimInfo*> const& which, although less 'traditional', is IMO easier to understand. (See http://www.xs4all.nl/~carlo17/cpp/const.qualifier.html )
-
indra/newview/llfloaterworldmap.cpp (Diff revision 3) -
If we use std::sort, we really should directly #include <algorithm> in this file, even if it already gets included indirectly (via other includes). The only exception I'd make would be if <algorithm> was already (directly) included by the corresponding header file, indra/newview/llfloaterworldmap.h, but that isn't the case here.
Review request changed
Updated (April 16, 2011, 1:52 p.m.)
-
- added Diff r4
New diff uploaded. Made a few changes suggested in Boroondas' comments.
One last (literally) tiny thing:
-
indra/newview/llfloaterworldmap.cpp (Diff revision 4) -
Put a space after the comma.
(No need for a new review-request diff for just that, I'd say.)
Other reviews