Skip to content

Commit 03c8bfb

Browse files
Merge pull request #50 from lacc97/no-constref
Reduce possibly expensive copying and allocating
2 parents f0cfe32 + 7229a40 commit 03c8bfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+582
-575
lines changed

source/matplot/axes_objects/bars.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace matplot {
8888
return res;
8989
}
9090

91-
std::string bars::legend_string(const std::string &title) {
91+
std::string bars::legend_string(std::string_view title) {
9292
std::string res;
9393
for (size_t i = 0; i < ys_.size(); ++i) {
9494
res += " keyentry with boxes fillstyle solid border rgb '" +
@@ -231,7 +231,7 @@ namespace matplot {
231231
return *this;
232232
}
233233

234-
class bars &bars::face_color(const std::string &color) {
234+
class bars &bars::face_color(std::string_view color) {
235235
face_color(to_array(color));
236236
return *this;
237237
}
@@ -268,7 +268,7 @@ namespace matplot {
268268
return *this;
269269
}
270270

271-
class bars &bars::edge_color(const std::string &color) {
271+
class bars &bars::edge_color(std::string_view color) {
272272
edge_color(to_array(color));
273273
return *this;
274274
}

source/matplot/axes_objects/bars.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace matplot {
3838
public /* xlim object virtual functions */:
3939
// std::string set_variables_string() override;
4040
std::string plot_string() override;
41-
std::string legend_string(const std::string &title) override;
41+
std::string legend_string(std::string_view title) override;
4242
std::string data_string() override;
4343
// std::string unset_variables_string() override;
4444
bool requires_colormap() override;
@@ -59,7 +59,7 @@ namespace matplot {
5959
class bars &face_color(const color_array &face_color);
6060
class bars &face_color(const std::array<float, 3> &face_color);
6161
class bars &face_color(std::initializer_list<float> face_color);
62-
class bars &face_color(const std::string &color);
62+
class bars &face_color(std::string_view color);
6363

6464
const std::vector<color_array> &face_colors() const;
6565
std::vector<color_array> &face_colors();
@@ -73,7 +73,7 @@ namespace matplot {
7373
class bars &edge_color(const color_array &edge_color);
7474
class bars &edge_color(const std::array<float, 3> &edge_color);
7575
class bars &edge_color(std::initializer_list<float> face_color);
76-
class bars &edge_color(const std::string &edge_color);
76+
class bars &edge_color(std::string_view edge_color);
7777

7878
const line_spec &edge_style() const;
7979
class bars &edge_style(const line_spec &edge_style);

source/matplot/axes_objects/circles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace matplot {
3737
return str;
3838
}
3939

40-
std::string circles::legend_string(const std::string &title) {
40+
std::string circles::legend_string(std::string_view title) {
4141
return " keyentry with circles linecolor var lw 4 fillstyle solid "
4242
"border linecolor 'black' title \"" +
4343
escape(title) + "\"";

source/matplot/axes_objects/circles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace matplot {
3434
public /* mandatory virtual functions */:
3535
// std::string set_variables_string() override;
3636
std::string plot_string() override;
37-
std::string legend_string(const std::string &title) override;
37+
std::string legend_string(std::string_view title) override;
3838
std::string data_string() override;
3939
// std::string unset_variables_string() override;
4040
bool requires_colormap() override;

source/matplot/axes_objects/contours.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace matplot {
1818
contours::contours(class axes_type *parent, const vector_2d &X,
1919
const vector_2d &Y, const vector_2d &Z,
20-
const std::string &line_spec)
20+
std::string_view line_spec)
2121
: axes_object(parent), X_data_(X), Y_data_(Y), Z_data_(Z),
2222
line_spec_(this, line_spec) {
2323
initialize_preprocessed_data();
@@ -26,7 +26,7 @@ namespace matplot {
2626
}
2727

2828
contours::contours(class axes_type *parent, const vector_2d &Z,
29-
const std::string &line_spec)
29+
std::string_view line_spec)
3030
: axes_object(parent), Z_data_(Z), line_spec_(this, line_spec) {
3131
initialize_preprocessed_data();
3232
contour_generator_ = QuadContourGenerator(X_data_, Y_data_, Z_data_,
@@ -465,7 +465,7 @@ namespace matplot {
465465
return std::make_pair(lowers, uppers);
466466
}
467467

468-
std::string contours::legend_string(const std::string &title) {
468+
std::string contours::legend_string(std::string_view title) {
469469
auto [min_level_it, max_level_it] =
470470
std::minmax_element(levels_.begin(), levels_.end());
471471
double zmax = *max_level_it;
@@ -1217,7 +1217,7 @@ namespace matplot {
12171217
return axes_object::axes_category::two_dimensional;
12181218
}
12191219

1220-
class contours &contours::line_style(const std::string &str) {
1220+
class contours &contours::line_style(std::string_view str) {
12211221
line_spec_.parse_string(str);
12221222
touch();
12231223
return *this;
@@ -1322,15 +1322,15 @@ namespace matplot {
13221322
}
13231323
}
13241324

1325-
class contours &contours::font(const std::string &font) {
1325+
class contours &contours::font(std::string_view font) {
13261326
font_ = font;
13271327
touch();
13281328
return *this;
13291329
}
13301330

13311331
const std::string &contours::font_weight() const { return font_weight_; }
13321332

1333-
class contours &contours::font_weight(const std::string &font_weight) {
1333+
class contours &contours::font_weight(std::string_view font_weight) {
13341334
font_weight_ = font_weight;
13351335
touch();
13361336
return *this;
@@ -1344,7 +1344,7 @@ namespace matplot {
13441344
return *this;
13451345
}
13461346

1347-
class contours &contours::font_color(const std::string &fc) {
1347+
class contours &contours::font_color(std::string_view fc) {
13481348
font_color(to_array(fc));
13491349
return *this;
13501350
}

source/matplot/axes_objects/contours.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ namespace matplot {
5252
/// \param line_spec Line properties
5353
contours(class axes_type *parent, const vector_2d &X,
5454
const vector_2d &Y, const vector_2d &Z,
55-
const std::string &line_spec = "");
55+
std::string_view line_spec = "");
5656

5757
contours(class axes_type *parent, const vector_2d &Z,
58-
const std::string &line_spec = "");
58+
std::string_view line_spec = "");
5959

6060
/// If we receive an axes_handle, we can convert it to a raw
6161
/// pointer because there is no ownership involved here
@@ -66,7 +66,7 @@ namespace matplot {
6666
public /* mandatory virtual functions */:
6767
std::string set_variables_string() override;
6868
std::string plot_string() override;
69-
std::string legend_string(const std::string &title) override;
69+
std::string legend_string(std::string_view title) override;
7070
std::string data_string() override;
7171
bool requires_colormap() override;
7272
double xmax() override;
@@ -76,7 +76,7 @@ namespace matplot {
7676
enum axes_object::axes_category axes_category() override;
7777

7878
public /* getters and setters */:
79-
class contours &line_style(const std::string &line_spec);
79+
class contours &line_style(std::string_view line_spec);
8080

8181
const matplot::line_spec &line_spec() const;
8282
matplot::line_spec &line_spec();
@@ -107,14 +107,14 @@ namespace matplot {
107107
class contours &font_size(const float &font_size);
108108

109109
const std::string font() const;
110-
class contours &font(const std::string &font);
110+
class contours &font(std::string_view font);
111111

112112
const std::string &font_weight() const;
113-
class contours &font_weight(const std::string &font_weight);
113+
class contours &font_weight(std::string_view font_weight);
114114

115115
const color_array &font_color() const;
116116
class contours &font_color(const color_array &font_color);
117-
class contours &font_color(const std::string &font_color);
117+
class contours &font_color(std::string_view font_color);
118118

119119
bool visible() const;
120120
class contours &visible(bool visible);

source/matplot/axes_objects/error_bar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace matplot {
1616
const std::vector<double> &y_pos_delta,
1717
const std::vector<double> &x_neg_delta,
1818
const std::vector<double> &x_pos_delta,
19-
const std::string &line_spec)
19+
std::string_view line_spec)
2020
: line(parent, x, y, line_spec), y_negative_delta_(y_neg_delta),
2121
y_positive_delta_(y_pos_delta), x_negative_delta_(x_neg_delta),
2222
x_positive_delta_(x_pos_delta) {}
2323

2424
error_bar::error_bar(class axes_type *parent, const std::vector<double> &x,
2525
const std::vector<double> &y,
2626
const std::vector<double> &error, error_bar::type type,
27-
const std::string &line_spec)
27+
std::string_view line_spec)
2828
: line(parent, x, y, line_spec),
2929
y_negative_delta_(type != error_bar::type::horizontal
3030
? error

source/matplot/axes_objects/error_bar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ namespace matplot {
2424
const std::vector<double> &y_pos_delta,
2525
const std::vector<double> &x_neg_delta,
2626
const std::vector<double> &x_pos_delta,
27-
const std::string &line_spec = "");
27+
std::string_view line_spec = "");
2828

2929
/// Construct with y error only
3030
error_bar(class axes_type *parent, const std::vector<double> &x_data,
3131
const std::vector<double> &y_data,
3232
const std::vector<double> &error,
3333
error_bar::type type = error_bar::type::vertical,
34-
const std::string &line_spec = "");
34+
std::string_view line_spec = "");
3535

3636
/// If we receive an axes_handle, we can convert it to a raw
3737
/// pointer because there is no ownership of the xlim

source/matplot/axes_objects/filled_area.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace matplot {
1414
const std::vector<double> &x,
1515
const std::vector<double> &y,
1616
const std::vector<double> &base_values,
17-
bool stacked, const std::string &line_spec)
17+
bool stacked, std::string_view line_spec)
1818
: line(parent, x, y, line_spec), stacked_(stacked),
1919
base_data_(base_values) {}
2020

source/matplot/axes_objects/filled_area.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace matplot {
2121
filled_area(class axes_type *parent, const std::vector<double> &x,
2222
const std::vector<double> &y,
2323
const std::vector<double> &base_values = {0.},
24-
bool stacked = true, const std::string &line_spec = "k-");
24+
bool stacked = true, std::string_view line_spec = "k-");
2525

2626
/// If we receive an axes_handle, we can convert it to a raw
2727
/// pointer because there is no ownership of the xlim

0 commit comments

Comments
 (0)