[Groonga-commit] groonga/grnxx at 9caf2b5 [master] Rename grnxx::Bytes::ptr() to grnxx::Bytes::data().

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Fri Jun 28 23:45:20 JST 2013


susumu.yata	2013-06-28 23:45:20 +0900 (Fri, 28 Jun 2013)

  New Revision: 9caf2b537e2abd985425ba76f8e8adbf88a35a11
  https://github.com/groonga/grnxx/commit/9caf2b537e2abd985425ba76f8e8adbf88a35a11

  Message:
    Rename grnxx::Bytes::ptr() to grnxx::Bytes::data().

  Modified files:
    lib/grnxx/bytes.hpp
    lib/grnxx/map/bytes_array.cpp
    lib/grnxx/map/bytes_store.cpp
    lib/grnxx/storage/storage_impl.cpp
    lib/grnxx/string_builder.cpp
    test/test_bytes.cpp
    test/test_map.cpp

  Modified: lib/grnxx/bytes.hpp (+18 -18)
===================================================================
--- lib/grnxx/bytes.hpp    2013-06-28 19:43:09 +0900 (42b1999)
+++ lib/grnxx/bytes.hpp    2013-06-28 23:45:20 +0900 (d355a3b)
@@ -32,14 +32,14 @@ class Bytes {
   // Trivial default constructor.
   Bytes() = default;
   // Create a reference to an empty (zero-size) sequence.
-  Bytes(nullptr_t) : ptr_(nullptr), size_(0) {}
+  Bytes(nullptr_t) : data_(nullptr), size_(0) {}
   // Create a reference to a zero-terminated string.
   Bytes(const char *str)
-      : ptr_(reinterpret_cast<const uint8_t *>(str)),
+      : data_(reinterpret_cast<const uint8_t *>(str)),
         size_(std::strlen(str)) {}
   // Create a reference to a sequence of bytes.
-  Bytes(const void *ptr, uint64_t size)
-      : ptr_(static_cast<const uint8_t *>(ptr)),
+  Bytes(const void *data, uint64_t size)
+      : data_(static_cast<const uint8_t *>(data)),
         size_(size) {}
 
   // Return true iff the sequence is not empty.
@@ -49,34 +49,34 @@ class Bytes {
 
   // Skip the first "n" bytes and extract the subsequent "m" bytes.
   Bytes extract(uint64_t n, uint64_t m) const {
-    return Bytes(ptr_ + n, m);
+    return Bytes(data_ + n, m);
   }
   // Remove the first "n" bytes and the last "m" bytes.
   Bytes trim(uint64_t n, uint64_t m) const {
-    return Bytes(ptr_ + n, size_ - n - m);
+    return Bytes(data_ + n, size_ - n - m);
   }
 
   // Extract the first "n" bytes.
   Bytes prefix(uint64_t n) const {
-    return Bytes(ptr_, n);
+    return Bytes(data_, n);
   }
   // Extract the last "n" bytes.
   Bytes suffix(uint64_t n) const {
-    return Bytes(ptr_ + size_ - n, n);
+    return Bytes(data_ + size_ - n, n);
   }
 
   // Remove the first "n" bytes.
   Bytes except_prefix(uint64_t n) const {
-    return Bytes(ptr_ + n, size_ - n);
+    return Bytes(data_ + n, size_ - n);
   }
   // Remove the last "n" bytes.
   Bytes except_suffix(uint64_t n) const {
-    return Bytes(ptr_, size_ - n);
+    return Bytes(data_, size_ - n);
   }
 
   // Return true iff "*this" == "rhs".
   bool operator==(const Bytes &rhs) const {
-    return (size_ == rhs.size_) && (std::memcmp(ptr_, rhs.ptr_, size_) == 0);
+    return (size_ == rhs.size_) && (std::memcmp(data_, rhs.data_, size_) == 0);
   }
   // Return true iff "*this" != "rhs".
   bool operator!=(const Bytes &rhs) const {
@@ -85,7 +85,7 @@ class Bytes {
   // Return true iff "*this" < "rhs".
   bool operator<(const Bytes &rhs) const {
     const uint64_t min_size = (size_ < rhs.size_) ? size_ : rhs.size_;
-    int result = std::memcmp(ptr_, rhs.ptr_, min_size);
+    int result = std::memcmp(data_, rhs.data_, min_size);
     return (result < 0) || ((result == 0) && (size_ < rhs.size_));
   }
   // Return true iff "*this" > "rhs".
@@ -106,7 +106,7 @@ class Bytes {
   // otherwise (if "*this" > "bytes").
   int compare(const Bytes &bytes) const {
     const uint64_t min_size = (size_ < bytes.size_) ? size_ : bytes.size_;
-    int result = std::memcmp(ptr_, bytes.ptr_, min_size);
+    int result = std::memcmp(data_, bytes.data_, min_size);
     if (result != 0) {
       return result;
     }
@@ -124,15 +124,15 @@ class Bytes {
 
   // Return the "i"-th byte.
   uint8_t operator[](uint64_t i) const {
-    return ptr_[i];
+    return data_[i];
   }
   // Return the starting address.
   const void *address() const {
-    return ptr_;
+    return data_;
   }
   // Return a pointer to the sequence.
-  const uint8_t *ptr() const {
-    return ptr_;
+  const uint8_t *data() const {
+    return data_;
   }
   // Return the number of bytes.
   uint64_t size() const {
@@ -140,7 +140,7 @@ class Bytes {
   }
 
  private:
-  const uint8_t *ptr_;
+  const uint8_t *data_;
   uint64_t size_;
 };
 

  Modified: lib/grnxx/map/bytes_array.cpp (+1 -1)
===================================================================
--- lib/grnxx/map/bytes_array.cpp    2013-06-28 19:43:09 +0900 (1137757)
+++ lib/grnxx/map/bytes_array.cpp    2013-06-28 23:45:20 +0900 (b6d4aec)
@@ -148,7 +148,7 @@ bool BytesArray::create_array(Storage *storage, uint32_t storage_node_id,
   header_ = static_cast<BytesArrayHeader *>(storage_node.body());
   *header_ = BytesArrayHeader();
   header_->default_value_size = default_value.size();
-  std::memcpy(header_ + 1, default_value.ptr(), default_value.size());
+  std::memcpy(header_ + 1, default_value.data(), default_value.size());
   default_value_ = Value(header_ + 1, default_value.size());
   ids_.reset(IDArray::create(storage, storage_node_id_,
                              BYTES_STORE_INVALID_BYTES_ID));

  Modified: lib/grnxx/map/bytes_store.cpp (+1 -1)
===================================================================
--- lib/grnxx/map/bytes_store.cpp    2013-06-28 19:43:09 +0900 (df04d34)
+++ lib/grnxx/map/bytes_store.cpp    2013-06-28 23:45:20 +0900 (550d593)
@@ -342,7 +342,7 @@ bool BytesStoreImpl::add(ValueArg bytes, uint64_t *bytes_id) {
   if (!page) {
     return false;
   }
-  std::memcpy(page + offset_in_page, bytes.ptr(), size);
+  std::memcpy(page + offset_in_page, bytes.data(), size);
   *bytes_id = get_bytes_id(offset, size);
   page_header->size_in_use += size;
   if (offset == header_->next_offset) {

  Modified: lib/grnxx/storage/storage_impl.cpp (+2 -2)
===================================================================
--- lib/grnxx/storage/storage_impl.cpp    2013-06-28 19:43:09 +0900 (e3dcaf8)
+++ lib/grnxx/storage/storage_impl.cpp    2013-06-28 23:45:20 +0900 (be95cd1)
@@ -1165,11 +1165,11 @@ char *StorageImpl::generate_path(uint16_t file_id) {
     return nullptr;
   }
   if (has_extension) {
-    std::memcpy(path, prefix.ptr(), prefix.size() - 4);
+    std::memcpy(path, prefix.data(), prefix.size() - 4);
     std::sprintf(path + prefix.size() - 4, "_%03d", file_id);
     std::strcpy(path + prefix.size(), ".grn");
   } else {
-    std::memcpy(path, prefix.ptr(), prefix.size());
+    std::memcpy(path, prefix.data(), prefix.size());
     std::sprintf(path + prefix.size(), "_%03d", file_id);
   }
   return path;

  Modified: lib/grnxx/string_builder.cpp (+1 -1)
===================================================================
--- lib/grnxx/string_builder.cpp    2013-06-28 19:43:09 +0900 (11a79b6)
+++ lib/grnxx/string_builder.cpp    2013-06-28 23:45:20 +0900 (4b3f356)
@@ -175,7 +175,7 @@ StringBuilder &operator<<(StringBuilder &builder, const void *value) {
 
 StringBuilder &operator<<(StringBuilder &builder, const Bytes &bytes) {
   // TODO: StringBuilder should support const uint_8 *.
-  return builder.append(reinterpret_cast<const char *>(bytes.ptr()),
+  return builder.append(reinterpret_cast<const char *>(bytes.data()),
                         bytes.size());
 }
 

  Modified: test/test_bytes.cpp (+8 -8)
===================================================================
--- test/test_bytes.cpp    2013-06-28 19:43:09 +0900 (c912ffa)
+++ test/test_bytes.cpp    2013-06-28 23:45:20 +0900 (083e1cd)
@@ -52,13 +52,13 @@ void test_extract() {
   grnxx::Bytes part = bytes.extract(5, 0);
 
   assert(!part);
-  assert(part.ptr() == (bytes.ptr() + 5));
+  assert(part.data() == (bytes.data() + 5));
   assert(part.size() == 0);
 
   part = bytes.extract(3, 5);
 
   assert(part);
-  assert(part.ptr() == (bytes.ptr() + 3));
+  assert(part.data() == (bytes.data() + 3));
   assert(part.size() == 5);
 }
 
@@ -67,13 +67,13 @@ void test_trim() {
   grnxx::Bytes part = bytes.extract(5, 0);
 
   assert(!part);
-  assert(part.ptr() == (bytes.ptr() + 5));
+  assert(part.data() == (bytes.data() + 5));
   assert(part.size() == 0);
 
   part = bytes.extract(3, 5);
 
   assert(part);
-  assert(part.ptr() == (bytes.ptr() + 3));
+  assert(part.data() == (bytes.data() + 3));
   assert(part.size() == 5);
 }
 
@@ -82,13 +82,13 @@ void test_prefix() {
   grnxx::Bytes prefix = bytes.prefix(0);
 
   assert(!prefix);
-  assert(prefix.ptr() == bytes.ptr());
+  assert(prefix.data() == bytes.data());
   assert(prefix.size() == 0);
 
   prefix = bytes.prefix(5);
 
   assert(prefix);
-  assert(prefix.ptr() == bytes.ptr());
+  assert(prefix.data() == bytes.data());
   assert(prefix.size() == 5);
 }
 
@@ -97,13 +97,13 @@ void test_suffix() {
   grnxx::Bytes suffix = bytes.suffix(0);
 
   assert(!suffix);
-  assert(suffix.ptr() == (bytes.ptr() + 10));
+  assert(suffix.data() == (bytes.data() + 10));
   assert(suffix.size() == 0);
 
   suffix = bytes.suffix(5);
 
   assert(suffix);
-  assert(suffix.ptr() == (bytes.ptr() + 5));
+  assert(suffix.data() == (bytes.data() + 5));
   assert(suffix.size() == 5);
 }
 

  Modified: test/test_map.cpp (+1 -1)
===================================================================
--- test/test_map.cpp    2013-06-28 19:43:09 +0900 (b328b8e)
+++ test/test_map.cpp    2013-06-28 23:45:20 +0900 (e235638)
@@ -131,7 +131,7 @@ void generate_random_keys(std::uint64_t num_keys,
   keyset.clear();
   while (keyset.size() < num_keys) {
     const grnxx::Bytes key = generate_random_key<grnxx::Bytes>();
-    keyset.insert(std::string(reinterpret_cast<const char *>(key.ptr()),
+    keyset.insert(std::string(reinterpret_cast<const char *>(key.data()),
                               key.size()));
   }
   keys->clear();
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る