Commit d7df60b2 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Replace WTF::NonCopyingSort with std::sort.

Now that move semantics exist, std::sort should work fine.

Change-Id: I47e017da1d1d9189fac65f319859d89b455090ca
Reviewed-on: https://chromium-review.googlesource.com/963983Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543693}
parent 5e3f37a8
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#include "core/inspector/ConsoleMessage.h" #include "core/inspector/ConsoleMessage.h"
#include "platform/wtf/ASCIICType.h" #include "platform/wtf/ASCIICType.h"
#include "platform/wtf/HashSet.h" #include "platform/wtf/HashSet.h"
#include "platform/wtf/NonCopyingSort.h"
namespace blink { namespace blink {
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "core/animation/InvalidatableInterpolation.h" #include "core/animation/InvalidatableInterpolation.h"
#include "core/animation/css/CSSAnimations.h" #include "core/animation/css/CSSAnimations.h"
#include "platform/runtime_enabled_features.h" #include "platform/runtime_enabled_features.h"
#include "platform/wtf/NonCopyingSort.h"
namespace blink { namespace blink {
...@@ -119,9 +118,8 @@ ActiveInterpolationsMap EffectStack::ActiveInterpolations( ...@@ -119,9 +118,8 @@ ActiveInterpolationsMap EffectStack::ActiveInterpolations(
if (effect_stack) { if (effect_stack) {
HeapVector<Member<SampledEffect>>& sampled_effects = HeapVector<Member<SampledEffect>>& sampled_effects =
effect_stack->sampled_effects_; effect_stack->sampled_effects_;
// std::sort doesn't work with OwnPtrs std::sort(sampled_effects.begin(), sampled_effects.end(),
NonCopyingSort(sampled_effects.begin(), sampled_effects.end(), CompareSampledEffects);
CompareSampledEffects);
effect_stack->RemoveRedundantSampledEffects(); effect_stack->RemoveRedundantSampledEffects();
for (const auto& sampled_effect : sampled_effects) { for (const auto& sampled_effect : sampled_effects) {
if (sampled_effect->GetPriority() != priority || if (sampled_effect->GetPriority() != priority ||
......
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
#include "core/css/MediaQuery.h" #include "core/css/MediaQuery.h"
#include <algorithm>
#include <memory> #include <memory>
#include "core/css/MediaQueryExp.h" #include "core/css/MediaQueryExp.h"
#include "core/html/parser/HTMLParserIdioms.h" #include "core/html/parser/HTMLParserIdioms.h"
#include "core/media_type_names.h" #include "core/media_type_names.h"
#include "platform/wtf/NonCopyingSort.h"
#include "platform/wtf/text/StringBuilder.h" #include "platform/wtf/text/StringBuilder.h"
namespace blink { namespace blink {
...@@ -92,7 +92,7 @@ MediaQuery::MediaQuery(RestrictorType restrictor, ...@@ -92,7 +92,7 @@ MediaQuery::MediaQuery(RestrictorType restrictor,
: restrictor_(restrictor), : restrictor_(restrictor),
media_type_(AttemptStaticStringCreation(media_type.LowerASCII())), media_type_(AttemptStaticStringCreation(media_type.LowerASCII())),
expressions_(std::move(expressions)) { expressions_(std::move(expressions)) {
NonCopyingSort(expressions_.begin(), expressions_.end(), ExpressionCompare); std::sort(expressions_.begin(), expressions_.end(), ExpressionCompare);
// Remove all duplicated expressions. // Remove all duplicated expressions.
MediaQueryExp key = MediaQueryExp::Invalid(); MediaQueryExp key = MediaQueryExp::Invalid();
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "core/html/forms/RangeInputType.h" #include "core/html/forms/RangeInputType.h"
#include <algorithm>
#include <limits> #include <limits>
#include "bindings/core/v8/ExceptionState.h" #include "bindings/core/v8/ExceptionState.h"
#include "core/dom/AXObjectCache.h" #include "core/dom/AXObjectCache.h"
...@@ -53,7 +54,6 @@ ...@@ -53,7 +54,6 @@
#include "core/input_type_names.h" #include "core/input_type_names.h"
#include "core/layout/LayoutSlider.h" #include "core/layout/LayoutSlider.h"
#include "platform/wtf/MathExtras.h" #include "platform/wtf/MathExtras.h"
#include "platform/wtf/NonCopyingSort.h"
namespace blink { namespace blink {
...@@ -375,8 +375,7 @@ void RangeInputType::UpdateTickMarkValues() { ...@@ -375,8 +375,7 @@ void RangeInputType::UpdateTickMarkValues() {
tick_mark_values_.push_back(ParseToNumber(option_value, Decimal::Nan())); tick_mark_values_.push_back(ParseToNumber(option_value, Decimal::Nan()));
} }
tick_mark_values_.ShrinkToFit(); tick_mark_values_.ShrinkToFit();
NonCopyingSort(tick_mark_values_.begin(), tick_mark_values_.end(), std::sort(tick_mark_values_.begin(), tick_mark_values_.end(), DecimalCompare);
DecimalCompare);
} }
Decimal RangeInputType::FindClosestTickMarkValue(const Decimal& value) { Decimal RangeInputType::FindClosestTickMarkValue(const Decimal& value) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "core/html/track/CueTimeline.h" #include "core/html/track/CueTimeline.h"
#include <algorithm>
#include "core/dom/events/Event.h" #include "core/dom/events/Event.h"
#include "core/html/media/HTMLMediaElement.h" #include "core/html/media/HTMLMediaElement.h"
#include "core/html/track/HTMLTrackElement.h" #include "core/html/track/HTMLTrackElement.h"
...@@ -11,7 +12,6 @@ ...@@ -11,7 +12,6 @@
#include "core/html/track/TextTrack.h" #include "core/html/track/TextTrack.h"
#include "core/html/track/TextTrackCue.h" #include "core/html/track/TextTrackCue.h"
#include "core/html/track/TextTrackCueList.h" #include "core/html/track/TextTrackCueList.h"
#include "platform/wtf/NonCopyingSort.h"
namespace blink { namespace blink {
...@@ -283,7 +283,7 @@ void CueTimeline::UpdateActiveCues(double movie_time) { ...@@ -283,7 +283,7 @@ void CueTimeline::UpdateActiveCues(double movie_time) {
// 12 - Sort the tasks in events in ascending time order (tasks with earlier // 12 - Sort the tasks in events in ascending time order (tasks with earlier
// times first). // times first).
NonCopyingSort(event_tasks.begin(), event_tasks.end(), EventTimeCueCompare); std::sort(event_tasks.begin(), event_tasks.end(), EventTimeCueCompare);
for (const auto& task : event_tasks) { for (const auto& task : event_tasks) {
if (!affected_tracks.Contains(task.second->track())) if (!affected_tracks.Contains(task.second->track()))
...@@ -311,8 +311,7 @@ void CueTimeline::UpdateActiveCues(double movie_time) { ...@@ -311,8 +311,7 @@ void CueTimeline::UpdateActiveCues(double movie_time) {
// 14 - Sort affected tracks in the same order as the text tracks appear in // 14 - Sort affected tracks in the same order as the text tracks appear in
// the media element's list of text tracks, and remove duplicates. // the media element's list of text tracks, and remove duplicates.
NonCopyingSort(affected_tracks.begin(), affected_tracks.end(), std::sort(affected_tracks.begin(), affected_tracks.end(), TrackIndexCompare);
TrackIndexCompare);
// 15 - For each text track in affected tracks, in the list order, queue a // 15 - For each text track in affected tracks, in the list order, queue a
// task to fire a simple event named cuechange at the TextTrack object, and, // task to fire a simple event named cuechange at the TextTrack object, and,
......
...@@ -93,7 +93,6 @@ jumbo_component("wtf") { ...@@ -93,7 +93,6 @@ jumbo_component("wtf") {
"ListHashSet.h", "ListHashSet.h",
"Locker.h", "Locker.h",
"MathExtras.h", "MathExtras.h",
"NonCopyingSort.h",
"Noncopyable.h", "Noncopyable.h",
"NotFound.h", "NotFound.h",
"Optional.h", "Optional.h",
......
/*
* Copyright (C) 2010 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WTF_NonCopyingSort_h
#define WTF_NonCopyingSort_h
namespace WTF {
using std::swap;
template <typename RandomAccessIterator, typename Predicate>
inline void SiftDown(RandomAccessIterator array,
ptrdiff_t start,
ptrdiff_t end,
Predicate compare_less) {
ptrdiff_t root = start;
while (root * 2 + 1 <= end) {
ptrdiff_t child = root * 2 + 1;
if (child < end && compare_less(array[child], array[child + 1]))
child++;
if (compare_less(array[root], array[child])) {
swap(array[root], array[child]);
root = child;
} else {
return;
}
}
}
template <typename RandomAccessIterator, typename Predicate>
inline void Heapify(RandomAccessIterator array,
ptrdiff_t count,
Predicate compare_less) {
ptrdiff_t start = (count - 2) / 2;
while (start >= 0) {
SiftDown(array, start, count - 1, compare_less);
start--;
}
}
template <typename RandomAccessIterator, typename Predicate>
void HeapSort(RandomAccessIterator start,
RandomAccessIterator end,
Predicate compare_less) {
ptrdiff_t count = end - start;
Heapify(start, count, compare_less);
ptrdiff_t end_index = count - 1;
while (end_index > 0) {
swap(start[end_index], start[0]);
SiftDown(start, 0, end_index - 1, compare_less);
end_index--;
}
}
template <typename RandomAccessIterator, typename Predicate>
inline void NonCopyingSort(RandomAccessIterator start,
RandomAccessIterator end,
Predicate compare_less) {
// heapsort happens to use only swaps, not copies, but the essential thing
// about this function is the fact that it does not copy, not the specific
// algorithm
HeapSort(start, end, compare_less);
}
} // namespace WTF
using WTF::NonCopyingSort;
#endif // WTF_NonCopyingSort_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment