aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorRichieSams2013-10-01 18:46:57 -0500
committerRichieSams2013-10-02 09:09:57 -0500
commitb913e9f8a330328a6600539ecd03754e19560f97 (patch)
tree4b9c044f176b55adf98945cd9d43e2b72a2cb35a /engines
parent1f9ba897b8aa8afe776928ecd5ca480b8b2fc3a8 (diff)
downloadscummvm-rg350-b913e9f8a330328a6600539ecd03754e19560f97.tar.gz
scummvm-rg350-b913e9f8a330328a6600539ecd03754e19560f97.tar.bz2
scummvm-rg350-b913e9f8a330328a6600539ecd03754e19560f97.zip
ZVISION: Update removeDuplicateEntries to preserve order
The new algorithm is potentially slower, but it doesn't need to use sort. Speed shouldn't be a problem because the function isn't used that often and in each case the size of the container is small.
Diffstat (limited to 'engines')
-rw-r--r--engines/zvision/utility.h28
1 files changed, 21 insertions, 7 deletions
diff --git a/engines/zvision/utility.h b/engines/zvision/utility.h
index af47de7fe0..14077080f5 100644
--- a/engines/zvision/utility.h
+++ b/engines/zvision/utility.h
@@ -61,20 +61,34 @@ void trimCommentsAndWhiteSpace(Common::String *string);
void dumpEveryResultAction(const Common::String &destFile);
/**
- * Removes all duplicate entries from container.
+ * Removes all duplicate entries from container. Relative order will be preserved.
*
- * @param container
- * @return
+ * @param container The Array to remove duplicate entries from
*/
template<class T>
void removeDuplicateEntries(Common::Array<T> &container) {
- Common::sort(container.begin(), container.end());
+ // Length of modified array
+ int newLength = 1;
+ int j;
+
+ for(int i = 1; i < container.size(); i++) {
+ for(j = 0; j < newLength; j++) {
+ if (container[i] == container[j]) {
+ break;
+ }
+ }
- for (uint i = 0; i + 1 < container.size(); ++i) {
- while (i + 1 < container.size() && container[i] == container[i + 1]) {
- container.remove_at(i + 1);
+ // If none of the values in index[0..j] of container are the same as array[i],
+ // then copy the current value to corresponding new position in array
+ if (j == newLength) {
+ container[newLength++] = container[i];
}
}
+
+ // Actually remove the unneeded space
+ while (container.size() < newLength) {
+ container.pop_back();
+ }
}
/**