New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Fix clang compilation #13335

Merged
merged 1 commit into from Feb 18, 2017

Conversation

Projects
None yet
4 participants
@byo
Contributor

byo commented Feb 9, 2017

Signed-off-by: Bartłomiej Święcki bartlomiej.swiecki@corp.ovh.com

@wjwithagen

@byo
Code now compiles on FreeBSD/Clang

@Liuchang0812

This comment has been minimized.

Contributor

Liuchang0812 commented Feb 14, 2017

hi, could we merge it now? I need this patch.

PerfHistogram(const PerfHistogram &other)
: m_axes_config(other.m_axes_config) {
PerfHistogram(const PerfHistogram &other) {
for (int i = 0; i < DIM; i++) {

This comment has been minimized.

@tchaikov

tchaikov Feb 14, 2017

Contributor

could use memcpy() for better performance.

This comment has been minimized.

@tchaikov

tchaikov Feb 15, 2017

Contributor

@byo on a second thought, we can also leverage std::array for this

diff --git a/src/common/perf_histogram.h b/src/common/perf_histogram.h
index 6d315905db..99274d765d 100644
--- a/src/common/perf_histogram.h
+++ b/src/common/perf_histogram.h
@@ -20,6 +20,7 @@
 #include "include/int_types.h"

 #include <memory>
+#include <array>

 class PerfHistogramCommon {
 public:
@@ -133,7 +134,7 @@ protected:
   std::unique_ptr<atomic64_t[]> m_rawData;

   /// Configuration of axes
-  axis_config_d m_axes_config[DIM];
+  std::array<axis_config_d,DIM> m_axes_config;

   /// Dump histogram counters to a formatter
   void dump_formatted_values(ceph::Formatter *f) const {
@@ -145,8 +146,8 @@ protected:
   /// Get number of all histogram counters
   int64_t get_raw_size() {
     int64_t ret = 1;
-    for (int i = 0; i < DIM; ++i) {
-      ret *= m_axes_config[i].m_buckets;
+    for (const auto &ac : m_axes_config) {
+      ret *= ac.m_buckets;
     }
     return ret;
   }

This comment has been minimized.

@byo

byo Feb 15, 2017

Contributor

@tchaikov Great idea! I guess that's what std::array was created for. And I'm almost sure that copying such array to another one would be automatically converted to memcpy if the element type is trivially copyable.

Will give it a try in a second.

@tchaikov

This comment has been minimized.

Contributor

tchaikov commented Feb 14, 2017

@Liuchang0812 it needs an approval and a qa run.

@Liuchang0812

This comment has been minimized.

Contributor

Liuchang0812 commented Feb 14, 2017

Bartłomiej Święcki
common: Fix clang compilation
Signed-off-by: Bartłomiej Święcki <bartlomiej.swiecki@corp.ovh.com>
@byo

This comment has been minimized.

Contributor

byo commented Feb 15, 2017

@tchaikov Changed as you suggested, looks much better now, also added small unit test to ensure the copy works correctly.

@byo

This comment has been minimized.

Contributor

byo commented Feb 15, 2017

jenkins retest this please

@tchaikov tchaikov self-assigned this Feb 15, 2017

@tchaikov tchaikov merged commit 2a05daa into ceph:master Feb 18, 2017

3 checks passed

Signed-off-by all commits in this PR are signed
Details
Unmodifed Submodules submodules for project are unmodified
Details
default Build finished.
Details

@byo byo deleted the ovh:wip-clang-compilation-fix branch Mar 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment