susumu.yata
null+****@clear*****
Fri May 24 17:20:32 JST 2013
susumu.yata 2013-05-24 17:20:32 +0900 (Fri, 24 May 2013) New Revision: d6669c5ead0aae9e8ee2ca3bfd76ea204733ba48 https://github.com/groonga/grnxx/commit/d6669c5ead0aae9e8ee2ca3bfd76ea204733ba48 Message: Update grnxx::GeoPoint to use the trivial default constructor. Modified files: lib/grnxx/geo_point.cpp lib/grnxx/geo_point.hpp Modified: lib/grnxx/geo_point.cpp (+3 -2) =================================================================== --- lib/grnxx/geo_point.cpp 2013-05-24 10:55:23 +0900 (e2cb3e6) +++ lib/grnxx/geo_point.cpp 2013-05-24 17:20:32 +0900 (4735281) @@ -22,8 +22,9 @@ namespace grnxx { uint64_t GeoPoint::interleave() const { - uint64_t latitude = static_cast<uint32_t>(point_.latitude); - uint64_t longitude = static_cast<uint32_t>(point_.longitude); + const Point point = reinterpret_cast<const Point &>(value_); + uint64_t latitude = static_cast<uint32_t>(point.latitude); + uint64_t longitude = static_cast<uint32_t>(point.longitude); latitude = (latitude | (latitude << 16)) & 0x0000FFFF0000FFFFULL; latitude = (latitude | (latitude << 8)) & 0x00FF00FF00FF00FFULL; latitude = (latitude | (latitude << 4)) & 0x0F0F0F0F0F0F0F0FULL; Modified: lib/grnxx/geo_point.hpp (+14 -17) =================================================================== --- lib/grnxx/geo_point.hpp 2013-05-24 10:55:23 +0900 (8f6e7ab) +++ lib/grnxx/geo_point.hpp 2013-05-24 17:20:32 +0900 (ec3ffb3) @@ -28,19 +28,19 @@ class StringBuilder; // Latitude and longitude (lat/long). union GeoPoint { + private: + struct Point { + int32_t latitude; + int32_t longitude; + }; + public: // Trivial default constructor. GeoPoint() = default; - // Copy the lat/long as uint64_t to force atomic copy. - GeoPoint(const GeoPoint &x) : value_(x.value_) {} // Copy the lat/long. - GeoPoint(int32_t latitude, int32_t longitude) - : point_{ latitude, longitude } {} - - // Assign the lat/long as uint64_t to force atomic assignment. - GeoPoint &operator=(const GeoPoint &x) { - value_ = x.value_; - return *this; + GeoPoint(int32_t latitude, int32_t longitude) : value_() { + Point point{ latitude, longitude }; + value_ = reinterpret_cast<const uint64_t &>(point); } // Interleave the lat/long. @@ -48,11 +48,11 @@ union GeoPoint { // Return the latitude. int32_t latitude() const { - return point_.latitude; + return reinterpret_cast<const Point &>(value_).latitude; } // Return the longitude. int32_t longitude() const { - return point_.longitude; + return reinterpret_cast<const Point &>(value_).longitude; } // Return the lat/long as uint64_t. uint64_t value() const { @@ -61,11 +61,11 @@ union GeoPoint { // Set the latitude. void set_latitude(int32_t x) { - point_.latitude = x; + reinterpret_cast<Point &>(value_).latitude = x; } // Set the longitude. void set_longitude(int32_t x) { - point_.longitude = x; + reinterpret_cast<Point &>(value_).longitude = x; } // Set the lat/long as uint64_t. void set_value(uint64_t x) { @@ -73,10 +73,7 @@ union GeoPoint { } private: - struct Point { - int32_t latitude; - int32_t longitude; - } point_; + // Force 8-byte alignment and atomic copy/assignment. uint64_t value_; }; -------------- next part -------------- HTML����������������������������... Download