Commit 72ff6c2d authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Switch away from using std::vector in blink::DiscreteSet

... in favor of WTF::Vector.

BUG=704136
R=guidou@chromium.org

Change-Id: I0a992e355e57b02195c0ac9484e396e89e456e0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303298
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#789608}
parent 5d0c1b13
......@@ -9,7 +9,6 @@
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
......@@ -26,8 +25,6 @@
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_processor_options.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h"
// TODO(crbug.com/704136): Replace the use of std::vector by WTF::Vector.
namespace blink {
using blink::AudioCaptureSettings;
......@@ -305,7 +302,7 @@ class EchoCancellationContainer {
device_parameters_(media::AudioParameters::UnavailableDeviceParams()),
is_device_capture_(true) {}
EchoCancellationContainer(std::vector<EchoCancellationType> allowed_values,
EchoCancellationContainer(Vector<EchoCancellationType> allowed_values,
bool has_active_source,
bool is_device_capture,
media::AudioParameters device_parameters,
......@@ -428,7 +425,7 @@ class EchoCancellationContainer {
}
static EchoCancellationTypeSet ToEchoCancellationTypes(const BoolSet ec_set) {
std::vector<EchoCancellationType> types;
Vector<EchoCancellationType> types;
if (ec_set.Contains(false))
types.push_back(EchoCancellationType::kEchoCancellationDisabled);
......@@ -884,22 +881,21 @@ class ProcessingBasedContainer {
// System echo cancellation should not be explicitly included in
// |echo_cancellation_type|. It is added automatically based on the value of
// |device_parameters|.
ProcessingBasedContainer(
ProcessingType processing_type,
std::vector<EchoCancellationType> echo_cancellation_types,
BoolSet auto_gain_control_set,
BoolSet goog_audio_mirroring_set,
BoolSet goog_experimental_echo_cancellation_set,
BoolSet goog_noise_suppression_set,
BoolSet goog_experimental_noise_suppression_set,
BoolSet goog_highpass_filter_set,
IntRangeSet sample_size_range,
IntRangeSet channels_range,
IntRangeSet sample_rate_range,
SourceInfo source_info,
bool is_device_capture,
media::AudioParameters device_parameters,
bool is_reconfiguration_allowed)
ProcessingBasedContainer(ProcessingType processing_type,
Vector<EchoCancellationType> echo_cancellation_types,
BoolSet auto_gain_control_set,
BoolSet goog_audio_mirroring_set,
BoolSet goog_experimental_echo_cancellation_set,
BoolSet goog_noise_suppression_set,
BoolSet goog_experimental_noise_suppression_set,
BoolSet goog_highpass_filter_set,
IntRangeSet sample_size_range,
IntRangeSet channels_range,
IntRangeSet sample_rate_range,
SourceInfo source_info,
bool is_device_capture,
media::AudioParameters device_parameters,
bool is_reconfiguration_allowed)
: processing_type_(processing_type),
sample_size_container_(sample_size_range),
channels_container_(channels_range),
......@@ -1094,7 +1090,7 @@ class DeviceContainer {
// For each processing based container, apply the constraints and only fail
// if all of them failed.
for (auto it = processing_based_containers_.begin();
for (auto* it = processing_based_containers_.begin();
it != processing_based_containers_.end();) {
DCHECK(!it->IsEmpty());
failed_constraint_name = it->ApplyConstraintSet(constraint_set);
......@@ -1103,7 +1099,7 @@ class DeviceContainer {
else
++it;
}
if (processing_based_containers_.empty()) {
if (processing_based_containers_.IsEmpty()) {
DCHECK_NE(failed_constraint_name, nullptr);
return failed_constraint_name;
}
......@@ -1268,7 +1264,7 @@ class DeviceContainer {
StringContainer device_id_container_;
StringContainer group_id_container_;
std::array<BooleanContainer, kNumBooleanContainerIds> boolean_containers_;
std::vector<ProcessingBasedContainer> processing_based_containers_;
Vector<ProcessingBasedContainer> processing_based_containers_;
};
constexpr DeviceContainer::BooleanPropertyContainerInfo
......@@ -1301,7 +1297,7 @@ class CandidatesContainer {
const char* ApplyConstraintSet(const ConstraintSet& constraint_set) {
const char* latest_failed_constraint_name = nullptr;
for (auto it = devices_.begin(); it != devices_.end();) {
for (auto* it = devices_.begin(); it != devices_.end();) {
DCHECK(!it->IsEmpty());
auto* failed_constraint_name = it->ApplyConstraintSet(constraint_set);
if (failed_constraint_name) {
......@@ -1339,11 +1335,11 @@ class CandidatesContainer {
return std::make_tuple(best_score, best_settings);
}
bool IsEmpty() const { return devices_.empty(); }
bool IsEmpty() const { return devices_.IsEmpty(); }
private:
std::string default_device_id_;
std::vector<DeviceContainer> devices_;
Vector<DeviceContainer> devices_;
};
std::string GetMediaStreamSource(const MediaConstraints& constraints) {
......
......@@ -95,9 +95,9 @@ bool IsPositiveFiniteAspectRatio(double aspect_ratio) {
// |vertices| must have 1 or 2 elements. Otherwise, behavior is undefined.
// This function is called when |point| has already been determined to be
// outside a polygon and |vertices| is the vertex or side closest to |point|.
Point GetClosestPointToVertexOrSide(const std::vector<Point> vertices,
Point GetClosestPointToVertexOrSide(const Vector<Point> vertices,
const Point& point) {
DCHECK(!vertices.empty());
DCHECK(!vertices.IsEmpty());
// If only a single vertex closest to |point|, return that vertex.
if (vertices.size() == 1U)
return vertices[0];
......@@ -309,7 +309,7 @@ Point ResolutionSet::SelectClosestPointToIdeal(
return intersection.ClosestPointTo(
Point(ideal_height, ideal_height * default_aspect_ratio));
}
std::vector<Point> closest_vertices =
Vector<Point> closest_vertices =
GetClosestVertices(&Point::height, ideal_height);
Point ideal_point(closest_vertices[0].height(),
closest_vertices[0].height() * default_aspect_ratio);
......@@ -323,7 +323,7 @@ Point ResolutionSet::SelectClosestPointToIdeal(
return intersection.ClosestPointTo(
Point(ideal_width / default_aspect_ratio, ideal_width));
}
std::vector<Point> closest_vertices =
Vector<Point> closest_vertices =
GetClosestVertices(&Point::width, ideal_width);
Point ideal_point(closest_vertices[0].width() / default_aspect_ratio,
closest_vertices[0].width());
......@@ -379,7 +379,7 @@ Point ResolutionSet::SelectClosestPointToIdealAspectRatio(
intersection.ClosestPointTo(default_height_point),
intersection.ClosestPointTo(default_width_point));
}
std::vector<Point> closest_vertices =
Vector<Point> closest_vertices =
GetClosestVertices(&Point::AspectRatio, ideal_aspect_ratio);
double actual_aspect_ratio = closest_vertices[0].AspectRatio();
Point default_height_point(default_height,
......@@ -402,7 +402,7 @@ Point ResolutionSet::ClosestPointTo(const Point& point) const {
DCHECK_GE(vertices.size(), 1U);
Point best_candidate(0, 0);
double best_distance = HUGE_VAL;
for (size_t i = 0; i < vertices.size(); ++i) {
for (WTF::wtf_size_t i = 0; i < vertices.size(); ++i) {
Point candidate = Point::ClosestPointInSegment(
point, vertices[i], vertices[(i + 1) % vertices.size()]);
double distance = Point::SquareEuclideanDistance(point, candidate);
......@@ -416,12 +416,12 @@ Point ResolutionSet::ClosestPointTo(const Point& point) const {
return best_candidate;
}
std::vector<Point> ResolutionSet::GetClosestVertices(double (Point::*accessor)()
const,
double value) const {
Vector<Point> ResolutionSet::GetClosestVertices(double (Point::*accessor)()
const,
double value) const {
DCHECK(!IsEmpty());
std::vector<Point> vertices = ComputeVertices();
std::vector<Point> closest_vertices;
Vector<Point> vertices = ComputeVertices();
Vector<Point> closest_vertices;
double best_diff = HUGE_VAL;
for (const auto& vertex : vertices) {
double diff;
......@@ -437,7 +437,7 @@ std::vector<Point> ResolutionSet::GetClosestVertices(double (Point::*accessor)()
closest_vertices.push_back(vertex);
}
}
DCHECK(!closest_vertices.empty());
DCHECK(!closest_vertices.IsEmpty());
DCHECK_LE(closest_vertices.size(), 2U);
return closest_vertices;
}
......@@ -481,8 +481,8 @@ ResolutionSet ResolutionSet::FromExactResolution(int width, int height) {
std::isnan(aspect_ratio) ? HUGE_VAL : aspect_ratio);
}
std::vector<Point> ResolutionSet::ComputeVertices() const {
std::vector<Point> vertices;
Vector<Point> ResolutionSet::ComputeVertices() const {
Vector<Point> vertices;
// Add vertices in counterclockwise order
// Start with (min_height, min_width) and continue along min_width.
TryAddVertex(&vertices, Point(min_height_, min_width_));
......@@ -521,7 +521,7 @@ std::vector<Point> ResolutionSet::ComputeVertices() const {
return vertices;
}
void ResolutionSet::TryAddVertex(std::vector<Point>* vertices,
void ResolutionSet::TryAddVertex(Vector<Point>* vertices,
const Point& point) const {
if (!ContainsPoint(point))
return;
......@@ -529,7 +529,7 @@ void ResolutionSet::TryAddVertex(std::vector<Point>* vertices,
// Add the point to the |vertices| if not already added.
// This is to prevent duplicates in case an aspect ratio intersects a width
// or height right on a vertex.
if (vertices->empty() ||
if (vertices->IsEmpty() ||
(*(vertices->end() - 1) != point && *vertices->begin() != point)) {
vertices->push_back(point);
}
......@@ -551,7 +551,7 @@ DiscreteSet<std::string> StringSetFromConstraint(
if (!constraint.HasExact())
return DiscreteSet<std::string>::UniversalSet();
std::vector<std::string> elements;
Vector<std::string> elements;
for (const auto& entry : constraint.Exact())
elements.push_back(entry.Ascii());
......
......@@ -9,13 +9,13 @@
#include <limits>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/gtest_prod_util.h"
#include "base/optional.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/mediastream/media_constraints.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
......@@ -151,10 +151,10 @@ class DiscreteSet {
// It is the responsibility of the caller to ensure that |elements| is not
// equivalent to the universal set and that |elements| has no repeated
// values. Takes ownership of |elements|.
explicit DiscreteSet(std::vector<T> elements)
explicit DiscreteSet(Vector<T> elements)
: is_universal_(false), elements_(std::move(elements)) {}
// Creates an empty set;
static DiscreteSet EmptySet() { return DiscreteSet(std::vector<T>()); }
static DiscreteSet EmptySet() { return DiscreteSet(Vector<T>()); }
static DiscreteSet UniversalSet() { return DiscreteSet(); }
DiscreteSet(const DiscreteSet& other) = default;
......@@ -167,9 +167,9 @@ class DiscreteSet {
return is_universal_ || base::Contains(elements_, value);
}
bool IsEmpty() const { return !is_universal_ && elements_.empty(); }
bool IsEmpty() const { return !is_universal_ && elements_.IsEmpty(); }
bool HasExplicitElements() const { return !elements_.empty(); }
bool HasExplicitElements() const { return !elements_.IsEmpty(); }
DiscreteSet Intersection(const DiscreteSet& other) const {
if (is_universal_)
......@@ -180,7 +180,7 @@ class DiscreteSet {
return EmptySet();
// Both sets have explicit elements.
std::vector<T> intersection;
Vector<T> intersection;
for (const auto& entry : elements_) {
if (base::Contains(other.elements_, entry))
intersection.push_back(entry);
......@@ -198,7 +198,7 @@ class DiscreteSet {
// Returns a reference to the list of elements in the set.
// Behavior is undefined if the set is universal.
const std::vector<T>& elements() const {
const Vector<T>& elements() const {
DCHECK(!is_universal_);
return elements_;
}
......@@ -207,7 +207,7 @@ class DiscreteSet {
private:
bool is_universal_;
std::vector<T> elements_;
Vector<T> elements_;
};
// Special case for DiscreteSet<bool> where it is easy to produce an explicit
......@@ -413,7 +413,7 @@ class MODULES_EXPORT ResolutionSet {
// consecutive vertices (modulo the size of the list) corresponds to a side of
// the polygon, with the vertices given in counterclockwise order.
// The list cannot contain more than six points.
std::vector<Point> ComputeVertices() const;
Vector<Point> ComputeVertices() const;
private:
// Implements SelectClosestPointToIdeal() for the case when only the ideal
......@@ -425,11 +425,11 @@ class MODULES_EXPORT ResolutionSet {
// Returns the vertices of the set that have the property accessed
// by |accessor| closest to |value|. The returned vector always has one or two
// elements. Behavior is undefined if the set is empty.
std::vector<Point> GetClosestVertices(double (Point::*accessor)() const,
double value) const;
Vector<Point> GetClosestVertices(double (Point::*accessor)() const,
double value) const;
// Adds |point| to |vertices| if |point| is included in this candidate set.
void TryAddVertex(std::vector<ResolutionSet::Point>* vertices,
void TryAddVertex(Vector<ResolutionSet::Point>* vertices,
const ResolutionSet::Point& point) const;
int min_height_;
......
......@@ -6,7 +6,6 @@
#include <cmath>
#include <string>
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_track.h"
......@@ -36,7 +35,7 @@ constexpr double kDefaultAspectRatio =
// Checks if |point| is an element of |vertices| using
// Point::IsApproximatelyEqualTo() to test for equality.
void VerticesContain(const std::vector<Point>& vertices, const Point& point) {
void VerticesContain(const Vector<Point>& vertices, const Point& point) {
bool result = false;
for (const auto& vertex : vertices) {
if (point.IsApproximatelyEqualTo(vertex)) {
......@@ -47,7 +46,7 @@ void VerticesContain(const std::vector<Point>& vertices, const Point& point) {
EXPECT_TRUE(result);
}
bool AreCounterclockwise(const std::vector<Point>& vertices) {
bool AreCounterclockwise(const Vector<Point>& vertices) {
// Single point or segment are trivial cases.
if (vertices.size() <= 2)
return true;
......@@ -63,7 +62,8 @@ bool AreCounterclockwise(const std::vector<Point>& vertices) {
// Compute orientation using the determinant of each diagonal in the
// polygon, using the first vertex as reference.
Point prev_diagonal = vertices[1] - vertices[0];
for (auto vertex = vertices.begin() + 2; vertex != vertices.end(); ++vertex) {
for (auto* vertex = vertices.begin() + 2; vertex != vertices.end();
++vertex) {
Point current_diagonal = *vertex - vertices[0];
// The determinant of the two diagonals returns the signed area of the
// parallelogram they generate. The area is positive if the diagonals are in
......@@ -81,8 +81,7 @@ bool AreCounterclockwise(const std::vector<Point>& vertices) {
// Determines if |vertices| is valid according to the contract for
// ResolutionCandidateSet::ComputeVertices().
bool AreValidVertices(const ResolutionSet& set,
const std::vector<Point>& vertices) {
bool AreValidVertices(const ResolutionSet& set, const Vector<Point>& vertices) {
// Verify that every vertex is included in |set|.
for (const auto& vertex : vertices) {
if (!set.ContainsPoint(vertex))
......@@ -1370,7 +1369,7 @@ TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetString) {
EXPECT_FALSE(set.HasExplicitElements());
// Constrained set.
set = StringSet(std::vector<std::string>({"a", "b", "c"}));
set = StringSet(Vector<std::string>({"a", "b", "c"}));
EXPECT_TRUE(set.Contains("a"));
EXPECT_TRUE(set.Contains("b"));
EXPECT_TRUE(set.Contains("c"));
......@@ -1389,8 +1388,8 @@ TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetString) {
EXPECT_FALSE(set.HasExplicitElements());
// Intersection.
set = StringSet(std::vector<std::string>({"a", "b", "c"}));
StringSet set2 = StringSet(std::vector<std::string>({"b", "c", "d"}));
set = StringSet(Vector<std::string>({"a", "b", "c"}));
StringSet set2 = StringSet(Vector<std::string>({"b", "c", "d"}));
auto intersection = set.Intersection(set2);
EXPECT_FALSE(intersection.Contains("a"));
EXPECT_TRUE(intersection.Contains("b"));
......@@ -1402,7 +1401,7 @@ TEST_F(MediaStreamConstraintsUtilSetsTest, DiscreteSetString) {
EXPECT_EQ(std::string("b"), intersection.FirstElement());
// Empty intersection.
set2 = StringSet(std::vector<std::string>({"d", "e", "f"}));
set2 = StringSet(Vector<std::string>({"d", "e", "f"}));
intersection = set.Intersection(set2);
EXPECT_FALSE(intersection.Contains("a"));
EXPECT_FALSE(intersection.Contains("b"));
......
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