[Groonga-commit] groonga/grnxx at 8852f1d [master] Use StringCRef instead of String. (#75)

Back to archive index

susumu.yata null+****@clear*****
Fri Sep 26 14:27:14 JST 2014


susumu.yata	2014-09-26 14:27:14 +0900 (Fri, 26 Sep 2014)

  New Revision: 8852f1d4428fad75509fc826629f76115d99f039
  https://github.com/groonga/grnxx/commit/8852f1d4428fad75509fc826629f76115d99f039

  Message:
    Use StringCRef instead of String. (#75)

  Modified files:
    include/grnxx/column.hpp
    include/grnxx/db.hpp
    include/grnxx/expression.hpp
    include/grnxx/index.hpp
    include/grnxx/table.hpp
    include/grnxx/types/data_types.hpp
    include/grnxx/types/options.hpp
    include/grnxx/types/string.hpp
    lib/grnxx/column.cpp
    lib/grnxx/column_impl.hpp
    lib/grnxx/db.cpp
    lib/grnxx/expression.cpp
    lib/grnxx/index.cpp
    lib/grnxx/name.cpp
    lib/grnxx/name.hpp
    lib/grnxx/table.cpp
    lib/grnxx/tree_index.hpp
    test/test_expression.cpp

  Modified: include/grnxx/column.hpp (+12 -12)
===================================================================
--- include/grnxx/column.hpp    2014-09-26 13:39:18 +0900 (30b9f40)
+++ include/grnxx/column.hpp    2014-09-26 14:27:14 +0900 (cf2a86e)
@@ -15,7 +15,7 @@ class Column {
     return table_;
   }
   // Return the name.
-  String name() const {
+  StringCRef name() const {
     return name_.ref();
   }
   // Return the data type.
@@ -43,7 +43,7 @@ class Column {
   // "error" != nullptr.
   virtual Index *create_index(
       Error *error,
-      String name,
+      const StringCRef &name,
       IndexType type,
       const IndexOptions &options = IndexOptions());
 
@@ -54,7 +54,7 @@ class Column {
   // "error" != nullptr.
   //
   // Note: Pointers to the removed index must not be used after deletion.
-  bool remove_index(Error *error, String name);
+  bool remove_index(Error *error, const StringCRef &name);
 
   // Rename an index named "name" to "new_name".
   //
@@ -62,8 +62,8 @@ class Column {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool rename_index(Error *error,
-                    String name,
-                    String new_name);
+                    const StringCRef &name,
+                    const StringCRef &new_name);
 
   // Change the order of indexes.
   //
@@ -77,8 +77,8 @@ class Column {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool reorder_index(Error *error,
-                     String name,
-                     String prev_name);
+                     const StringCRef &name,
+                     const StringCRef &prev_name);
 
   // Get an index identified by "index_id".
   //
@@ -96,7 +96,7 @@ class Column {
   // On success, returns a pointer to the index.
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
-  Index *find_index(Error *error, String name) const;
+  Index *find_index(Error *error, const StringCRef &name) const;
 
   // Set a value.
   //
@@ -131,7 +131,7 @@ class Column {
   // "error" != nullptr.
   bool initialize_base(Error *error,
                        Table *table,
-                       String name,
+                       const StringCRef &name,
                        DataType data_type,
                        const ColumnOptions &options = ColumnOptions());
 
@@ -144,7 +144,7 @@ class Column {
   static unique_ptr<Column> create(
       Error *error,
       Table *table,
-      String name,
+      const StringCRef &name,
       DataType data_type,
       const ColumnOptions &options = ColumnOptions());
 
@@ -153,7 +153,7 @@ class Column {
   // On success, returns true.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool rename(Error *error, String new_name);
+  bool rename(Error *error, const StringCRef &new_name);
 
   // Return whether the column is removable or not.
   bool is_removable();
@@ -181,7 +181,7 @@ class Column {
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
   Index *find_index_with_id(Error *error,
-                            String name,
+                            const StringCRef &name,
                             Int *column_id) const;
 
   friend class Table;

  Modified: include/grnxx/db.hpp (+12 -12)
===================================================================
--- include/grnxx/db.hpp    2014-09-26 13:39:18 +0900 (a90fbee)
+++ include/grnxx/db.hpp    2014-09-26 14:27:14 +0900 (5b317f1)
@@ -20,7 +20,7 @@ class DB {
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
   Table *create_table(Error *error,
-                      String name,
+                      const StringCRef &name,
                       const TableOptions &options = TableOptions());
 
   // Remove a table named "name".
@@ -30,7 +30,7 @@ class DB {
   // "error" != nullptr.
   //
   // Note: Pointers to the removed table must not be used after deletion.
-  bool remove_table(Error *error, String name);
+  bool remove_table(Error *error, const StringCRef &name);
 
   // Rename a table named "name" to "new_name".
   //
@@ -38,8 +38,8 @@ class DB {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool rename_table(Error *error,
-                    String name,
-                    String new_name);
+                    const StringCRef &name,
+                    const StringCRef &new_name);
 
   // Change the order of tables.
   //
@@ -52,8 +52,8 @@ class DB {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool reorder_table(Error *error,
-                     String name,
-                     String prev_name);
+                     const StringCRef &name,
+                     const StringCRef &prev_name);
 
   // Get a table identified by "table_id".
   //
@@ -71,7 +71,7 @@ class DB {
   // On success, returns a pointer to the table.
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
-  Table *find_table(Error *error, String name) const;
+  Table *find_table(Error *error, const StringCRef &name) const;
 
   // TODO: Not supported yet.
   //
@@ -84,7 +84,7 @@ class DB {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool save(Error *error,
-            String path,
+            const StringCRef &path,
             const DBOptions &options = DBOptions()) const;
 
  private:
@@ -98,11 +98,11 @@ class DB {
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
   Table *find_table_with_id(Error *error,
-                            String name,
+                            const StringCRef &name,
                             Int *table_id) const;
 
   friend unique_ptr<DB> open_db(Error *error,
-                                String path,
+                                const StringCRef &path,
                                 const DBOptions &options);
 };
 
@@ -116,7 +116,7 @@ class DB {
 // On failure, returns nullptr and stores error information into "*error" if
 // "error" != nullptr.
 unique_ptr<DB> open_db(Error *error,
-                       String path,
+                       const StringCRef &path,
                        const DBOptions &options = DBOptions());
 
 // TODO: Not supported yet.
@@ -127,7 +127,7 @@ unique_ptr<DB> open_db(Error *error,
 // On failure, returns false and stores error information into "*error" if
 // "error" != nullptr.
 bool remove_db(Error *error,
-               String path,
+               const StringCRef &path,
                const DBOptions &options = DBOptions());
 
 }  // namespace grnxx

  Modified: include/grnxx/expression.hpp (+1 -1)
===================================================================
--- include/grnxx/expression.hpp    2014-09-26 13:39:18 +0900 (23a2333)
+++ include/grnxx/expression.hpp    2014-09-26 14:27:14 +0900 (bef34fc)
@@ -232,7 +232,7 @@ class ExpressionBuilder {
   // On success, returns true.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool push_column(Error *error, String name);
+  bool push_column(Error *error, const StringCRef &name);
 
   // Push a node associated with an operator.
   //

  Modified: include/grnxx/index.hpp (+4 -4)
===================================================================
--- include/grnxx/index.hpp    2014-09-26 13:39:18 +0900 (403fe72)
+++ include/grnxx/index.hpp    2014-09-26 14:27:14 +0900 (e37ca53)
@@ -74,7 +74,7 @@ class Index {
     return column_;
   }
   // Return the name.
-  String name() const {
+  StringCRef name() const {
     return name_.ref();
   }
   // Return the index type.
@@ -149,7 +149,7 @@ class Index {
   // "error" != nullptr.
   bool initialize_base(Error *error,
                        Column *column,
-                       String name,
+                       const StringCRef &name,
                        IndexType type,
                        const IndexOptions &options);
 
@@ -162,7 +162,7 @@ class Index {
   static unique_ptr<Index> create(
       Error *error,
       Column *column,
-      String name,
+      const StringCRef &name,
       IndexType type,
       const IndexOptions &options = IndexOptions());
 
@@ -171,7 +171,7 @@ class Index {
   // Returns true on success.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool rename(Error *error, String new_name);
+  bool rename(Error *error, const StringCRef &new_name);
 
   // Return whether the index is removable or not.
   bool is_removable();

  Modified: include/grnxx/table.hpp (+12 -12)
===================================================================
--- include/grnxx/table.hpp    2014-09-26 13:39:18 +0900 (5652ba5)
+++ include/grnxx/table.hpp    2014-09-26 14:27:14 +0900 (cdcb88f)
@@ -15,7 +15,7 @@ class Table {
     return db_;
   }
   // Return the name.
-  String name() const {
+  StringCRef name() const {
     return name_.ref();
   }
   // Return the number of columns.
@@ -41,7 +41,7 @@ class Table {
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
   Column *create_column(Error *error,
-                        String name,
+                        const StringCRef &name,
                         DataType data_type,
                         const ColumnOptions &options = ColumnOptions());
 
@@ -52,7 +52,7 @@ class Table {
   // "error" != nullptr.
   //
   // Note: Pointers to the removed column must not be used after deletion.
-  bool remove_column(Error *error, String name);
+  bool remove_column(Error *error, const StringCRef &name);
 
   // Rename a column named "name" to "new_name".
   //
@@ -60,8 +60,8 @@ class Table {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool rename_column(Error *error,
-                     String name,
-                     String new_name);
+                     const StringCRef &name,
+                     const StringCRef &new_name);
 
   // Change the order of columns.
   //
@@ -75,8 +75,8 @@ class Table {
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
   bool reorder_column(Error *error,
-                      String name,
-                      String prev_name);
+                      const StringCRef &name,
+                      const StringCRef &prev_name);
 
   // Get a column identified by "column_id".
   //
@@ -94,7 +94,7 @@ class Table {
   // On success, returns a pointer to the column.
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
-  Column *find_column(Error *error, String name) const;
+  Column *find_column(Error *error, const StringCRef &name) const;
 
   // Set the key attribute to the column named "name".
   //
@@ -103,7 +103,7 @@ class Table {
   // On success, returns true.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool set_key_column(Error *error, String name);
+  bool set_key_column(Error *error, const StringCRef &name);
 
   // Unset the key attribute of the key column.
   //
@@ -200,7 +200,7 @@ class Table {
   static unique_ptr<Table> create(
       Error *error,
       DB *db,
-      String name,
+      const StringCRef &name,
       const TableOptions &options = TableOptions());
 
   Table();
@@ -227,7 +227,7 @@ class Table {
   // On success, returns true.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool rename(Error *error, String new_name);
+  bool rename(Error *error, const StringCRef &new_name);
 
   // Return whether the table is removable or not.
   bool is_removable();
@@ -238,7 +238,7 @@ class Table {
   // On failure, returns nullptr and stores error information into "*error" if
   // "error" != nullptr.
   Column *find_column_with_id(Error *error,
-                              String name,
+                              const StringCRef &name,
                               Int *column_id) const;
 
   friend class DB;

  Modified: include/grnxx/types/data_types.hpp (+2 -2)
===================================================================
--- include/grnxx/types/data_types.hpp    2014-09-26 13:39:18 +0900 (311dc40)
+++ include/grnxx/types/data_types.hpp    2014-09-26 14:27:14 +0900 (1299335)
@@ -13,8 +13,8 @@ namespace grnxx {
 
 // GeoPoint is provided in grnxx/types/geo_point.hpp.
 
-// String is provided in grnxx/types/string.hpp.
-using Text = String;
+// StringCRef is provided in grnxx/types/string.hpp.
+using Text = StringCRef;
 
 // Vector<T> are provided in grnxx/types/vector.hpp.
 using BoolVector     = Vector<Bool>;

  Modified: include/grnxx/types/options.hpp (+1 -1)
===================================================================
--- include/grnxx/types/options.hpp    2014-09-26 13:39:18 +0900 (e5a4247)
+++ include/grnxx/types/options.hpp    2014-09-26 14:27:14 +0900 (4f85ab5)
@@ -17,7 +17,7 @@ struct TableOptions {
 
 struct ColumnOptions {
   // The referenced (parent) table.
-  String ref_table_name;
+  StringCRef ref_table_name;
 
   ColumnOptions();
 };

  Modified: include/grnxx/types/string.hpp (+2 -66)
===================================================================
--- include/grnxx/types/string.hpp    2014-09-26 13:39:18 +0900 (c73ffdf)
+++ include/grnxx/types/string.hpp    2014-09-26 14:27:14 +0900 (63fff75)
@@ -13,9 +13,7 @@ class StringCRef {
   // The default constructor does nothing.
   StringCRef() = default;
   // Refer to a zero-terminated string.
-  StringCRef(const char *arg)
-      : data_(arg),
-        size_(arg ? std::strlen(arg) : 0) {}
+  StringCRef(const char *arg) : data_(arg), size_(std::strlen(arg)) {}
   // Refer to an arbitrary byte string.
   StringCRef(const char *data, Int size) : data_(data), size_(size) {}
 
@@ -181,69 +179,7 @@ inline bool operator>=(const char *lhs, const StringCRef &rhs) {
   return rhs <= lhs;
 }
 
-// Reference to a byte string.
-class String {
- public:
-  // The default constructor does nothing.
-  String() = default;
-
-  // Refer to a zero-terminated string.
-  String(const char *str) : data_(str), size_(str ? std::strlen(str) : 0) {}
-
-  // Refer to an arbitrary byte string.
-  String(const char *data, Int size) : data_(data), size_(size) {}
-
-  const char &operator[](Int i) const {
-    return data_[i];
-  }
-
-  const char *data() const {
-    return data_;
-  }
-  Int size() const {
-    return size_;
-  }
-
- private:
-  const char *data_;
-  Int size_;
-};
-
-inline bool operator==(String lhs, String rhs) {
-  return (lhs.size() == rhs.size()) &&
-         (std::memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
-}
-
-inline bool operator!=(String lhs, String rhs) {
-  return (lhs.size() != rhs.size()) ||
-         (std::memcmp(lhs.data(), rhs.data(), lhs.size()) != 0);
-}
-
-inline bool operator<(String lhs, String rhs) {
-  Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
-  int result = std::memcmp(lhs.data(), rhs.data(), min_size);
-  return (result < 0) || ((result == 0) && (lhs.size() < rhs.size()));
-}
-
-inline bool operator>(String lhs, String rhs) {
-  Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
-  int result = std::memcmp(lhs.data(), rhs.data(), min_size);
-  return (result > 0) || ((result == 0) && (lhs.size() > rhs.size()));
-}
-
-inline bool operator<=(String lhs, String rhs) {
-  Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
-  int result = std::memcmp(lhs.data(), rhs.data(), min_size);
-  return (result < 0) || ((result == 0) && (lhs.size() <= rhs.size()));
-}
-
-inline bool operator>=(String lhs, String rhs) {
-  Int min_size = lhs.size() < rhs.size() ? lhs.size() : rhs.size();
-  int result = std::memcmp(lhs.data(), rhs.data(), min_size);
-  return (result > 0) || ((result == 0) && (lhs.size() >= rhs.size()));
-}
-
-using Text = String;
+using Text = StringCRef;
 
 }  // namespace grnxx
 

  Modified: lib/grnxx/column.cpp (+18 -18)
===================================================================
--- lib/grnxx/column.cpp    2014-09-26 13:39:18 +0900 (039da1b)
+++ lib/grnxx/column.cpp    2014-09-26 14:27:14 +0900 (a567256)
@@ -11,7 +11,7 @@ namespace grnxx {
 Column::~Column() {}
 
 Index *Column::create_index(Error *error,
-                            String name,
+                            const StringCRef &name,
                             IndexType type,
                             const IndexOptions &options) {
   if (find_index(nullptr, name)) {
@@ -32,7 +32,7 @@ Index *Column::create_index(Error *error,
   return indexes_.back().get();
 }
 
-bool Column::remove_index(Error *error, String name) {
+bool Column::remove_index(Error *error, const StringCRef &name) {
   Int index_id;
   if (!find_index_with_id(error, name, &index_id)) {
     return false;
@@ -48,8 +48,8 @@ bool Column::remove_index(Error *error, String name) {
 }
 
 bool Column::rename_index(Error *error,
-                          String name,
-                          String new_name) {
+                          const StringCRef &name,
+                          const StringCRef &new_name) {
   Int index_id;
   if (!find_index_with_id(error, name, &index_id)) {
     return false;
@@ -67,8 +67,8 @@ bool Column::rename_index(Error *error,
 }
 
 bool Column::reorder_index(Error *error,
-                           String name,
-                           String prev_name) {
+                           const StringCRef &name,
+                           const StringCRef &prev_name) {
   Int index_id;
   if (!find_index_with_id(error, name, &index_id)) {
     return false;
@@ -94,7 +94,7 @@ bool Column::reorder_index(Error *error,
   return true;
 }
 
-Index *Column::find_index(Error *error, String name) const {
+Index *Column::find_index(Error *error, const StringCRef &name) const {
   for (Int index_id = 0; index_id < num_indexes(); ++index_id) {
     if (name == indexes_[index_id]->name()) {
       return indexes_[index_id].get();
@@ -116,7 +116,7 @@ bool Column::get(Error *error, Int, Datum *) const {
 
 unique_ptr<Column> Column::create(Error *error,
                                   Table *table,
-                                  String name,
+                                  const StringCRef &name,
                                   DataType data_type,
                                   const ColumnOptions &options) {
   switch (data_type) {
@@ -167,7 +167,7 @@ Column::Column()
 
 bool Column::initialize_base(Error *error,
                              Table *table,
-                             String name,
+                             const StringCRef &name,
                              DataType data_type,
                              const ColumnOptions &options) {
   table_ = table;
@@ -187,7 +187,7 @@ bool Column::initialize_base(Error *error,
   return true;
 }
 
-bool Column::rename(Error *error, String new_name) {
+bool Column::rename(Error *error, const StringCRef &new_name) {
   return name_.assign(error, new_name);
 }
 
@@ -203,7 +203,7 @@ bool Column::set_initial_key(Error *error, Int, const Datum &) {
 }
 
 Index *Column::find_index_with_id(Error *error,
-                                  String name,
+                                  const StringCRef &name,
                                   Int *index_id) const {
   for (Int i = 0; i < num_indexes(); ++i) {
     if (name == indexes_[i]->name()) {
@@ -263,7 +263,7 @@ bool ColumnImpl<T>::get(Error *error, Int row_id, Datum *datum) const {
 template <typename T>
 unique_ptr<ColumnImpl<T>> ColumnImpl<T>::create(Error *error,
                                                 Table *table,
-                                                String name,
+                                                const StringCRef &name,
                                                 const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {
@@ -360,7 +360,7 @@ bool ColumnImpl<Int>::get(Error *error, Int row_id, Datum *datum) const {
 unique_ptr<ColumnImpl<Int>> ColumnImpl<Int>::create(
     Error *error,
     Table *table,
-    String name,
+    const StringCRef &name,
     const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {
@@ -468,7 +468,7 @@ bool ColumnImpl<Text>::get(Error *error, Int row_id, Datum *datum) const {
 unique_ptr<ColumnImpl<Text>> ColumnImpl<Text>::create(
     Error *error,
     Table *table,
-    String name,
+    const StringCRef &name,
     const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {
@@ -572,7 +572,7 @@ bool ColumnImpl<Vector<Int>>::get(Error *error, Int row_id,
 unique_ptr<ColumnImpl<Vector<Int>>> ColumnImpl<Vector<Int>>::create(
     Error *error,
     Table *table,
-    String name,
+    const StringCRef &name,
     const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {
@@ -658,7 +658,7 @@ bool ColumnImpl<Vector<Float>>::get(Error *error, Int row_id,
 unique_ptr<ColumnImpl<Vector<Float>>> ColumnImpl<Vector<Float>>::create(
     Error *error,
     Table *table,
-    String name,
+    const StringCRef &name,
     const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {
@@ -745,7 +745,7 @@ bool ColumnImpl<Vector<GeoPoint>>::get(Error *error, Int row_id,
 unique_ptr<ColumnImpl<Vector<GeoPoint>>> ColumnImpl<Vector<GeoPoint>>::create(
     Error *error,
     Table *table,
-    String name,
+    const StringCRef &name,
     const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {
@@ -831,7 +831,7 @@ bool ColumnImpl<Vector<Text>>::get(Error *error, Int row_id,
 unique_ptr<ColumnImpl<Vector<Text>>> ColumnImpl<Vector<Text>>::create(
     Error *error,
     Table *table,
-    String name,
+    const StringCRef &name,
     const ColumnOptions &options) {
   unique_ptr<ColumnImpl> column(new (nothrow) ColumnImpl);
   if (!column) {

  Modified: lib/grnxx/column_impl.hpp (+8 -8)
===================================================================
--- lib/grnxx/column_impl.hpp    2014-09-26 13:39:18 +0900 (8eaf571)
+++ lib/grnxx/column_impl.hpp    2014-09-26 14:27:14 +0900 (dbf4903)
@@ -22,7 +22,7 @@ class ColumnImpl : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();
@@ -67,7 +67,7 @@ class ColumnImpl<Int> : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();
@@ -112,7 +112,7 @@ class ColumnImpl<Text> : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();
@@ -134,7 +134,7 @@ class ColumnImpl<Text> : public Column {
     } else {
       // The size of a long text is stored in front of the body.
       size = *reinterpret_cast<const Int *>(&bodies_[offset]);
-      return String(&bodies_[offset + sizeof(Int)], size);
+      return StringCRef(&bodies_[offset + sizeof(Int)], size);
     }
   }
 
@@ -169,7 +169,7 @@ class ColumnImpl<Vector<Int>> : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();
@@ -226,7 +226,7 @@ class ColumnImpl<Vector<Float>> : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();
@@ -283,7 +283,7 @@ class ColumnImpl<Vector<GeoPoint>> : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();
@@ -342,7 +342,7 @@ class ColumnImpl<Vector<Text>> : public Column {
   // "error" != nullptr.
   static unique_ptr<ColumnImpl> create(Error *error,
                                        Table *table,
-                                       String name,
+                                       const StringCRef &name,
                                        const ColumnOptions &options);
 
   ~ColumnImpl();

  Modified: lib/grnxx/db.cpp (+11 -11)
===================================================================
--- lib/grnxx/db.cpp    2014-09-26 13:39:18 +0900 (dde2824)
+++ lib/grnxx/db.cpp    2014-09-26 14:27:14 +0900 (14edb20)
@@ -7,7 +7,7 @@ namespace grnxx {
 DB::~DB() {}
 
 Table *DB::create_table(Error *error,
-                        String name,
+                        const StringCRef &name,
                         const TableOptions &options) {
   if (find_table(nullptr, name)) {
     GRNXX_ERROR_SET(error, ALREADY_EXISTS,
@@ -27,7 +27,7 @@ Table *DB::create_table(Error *error,
   return tables_.back().get();
 }
 
-bool DB::remove_table(Error *error, String name) {
+bool DB::remove_table(Error *error, const StringCRef &name) {
   Int table_id;
   if (!find_table_with_id(error, name, &table_id)) {
     return false;
@@ -43,8 +43,8 @@ bool DB::remove_table(Error *error, String name) {
 }
 
 bool DB::rename_table(Error *error,
-                      String name,
-                      String new_name) {
+                      const StringCRef &name,
+                      const StringCRef &new_name) {
   Int table_id;
   if (!find_table_with_id(error, name, &table_id)) {
     return false;
@@ -62,8 +62,8 @@ bool DB::rename_table(Error *error,
 }
 
 bool DB::reorder_table(Error *error,
-                       String name,
-                       String prev_name) {
+                       const StringCRef &name,
+                       const StringCRef &prev_name) {
   Int table_id;
   if (!find_table_with_id(error, name, &table_id)) {
     return false;
@@ -89,7 +89,7 @@ bool DB::reorder_table(Error *error,
   return true;
 }
 
-Table *DB::find_table(Error *error, String name) const {
+Table *DB::find_table(Error *error, const StringCRef &name) const {
   for (Int table_id = 0; table_id < num_tables(); ++table_id) {
     if (name == tables_[table_id]->name()) {
       return tables_[table_id].get();
@@ -101,7 +101,7 @@ Table *DB::find_table(Error *error, String name) const {
 }
 
 bool DB::save(Error *error,
-              String,
+              const StringCRef &,
               const DBOptions &) const {
   // TODO: Named DB is not supported yet.
   GRNXX_ERROR_SET(error, NOT_SUPPORTED_YET, "Not supported yet");
@@ -111,7 +111,7 @@ bool DB::save(Error *error,
 DB::DB() : tables_() {}
 
 Table *DB::find_table_with_id(Error *error,
-                              String name,
+                              const StringCRef &name,
                               Int *table_id) const {
   for (Int i = 0; i < num_tables(); ++i) {
     if (name == tables_[i]->name()) {
@@ -127,7 +127,7 @@ Table *DB::find_table_with_id(Error *error,
 }
 
 unique_ptr<DB> open_db(Error *error,
-                       String path,
+                       const StringCRef &path,
                        const DBOptions &) {
   if (path.size() != 0) {
     // TODO: Named DB is not supported yet.
@@ -142,7 +142,7 @@ unique_ptr<DB> open_db(Error *error,
   return db;
 }
 
-bool remove_db(Error *error, String, const DBOptions &) {
+bool remove_db(Error *error, const StringCRef &, const DBOptions &) {
   // TODO: Named DB is not supported yet.
   GRNXX_ERROR_SET(error, NOT_SUPPORTED_YET, "Not supported yet");
   return false;

  Modified: lib/grnxx/expression.cpp (+5 -5)
===================================================================
--- lib/grnxx/expression.cpp    2014-09-26 13:39:18 +0900 (49b8fdb)
+++ lib/grnxx/expression.cpp    2014-09-26 14:27:14 +0900 (b79bce0)
@@ -2899,7 +2899,7 @@ class Builder {
   // On success, returns true.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool push_column(Error *error, String name);
+  bool push_column(Error *error, const StringCRef &name);
 
   // Push an operator.
   //
@@ -2947,7 +2947,7 @@ class Builder {
   // Create a node associated with a constant.
   unique_ptr<Node> create_constant_node(Error *error, const Datum &datum);
   // Create a node associated with a column.
-  unique_ptr<Node> create_column_node(Error *error, String name);
+  unique_ptr<Node> create_column_node(Error *error, const StringCRef &name);
 
   // Push a unary operator.
   bool push_unary_operator(Error *error, OperatorType operator_type);
@@ -3057,7 +3057,7 @@ bool Builder::push_score(Error *error) {
   return true;
 }
 
-bool Builder::push_column(Error *error, String name) {
+bool Builder::push_column(Error *error, const StringCRef &name) {
   // Reserve a space for a new node.
   if (!stack_.reserve(error, stack_.size() + 1)) {
     return false;
@@ -3192,7 +3192,7 @@ unique_ptr<Node> Builder::create_constant_node(
 
 unique_ptr<Node> Builder::create_column_node(
     Error *error,
-    String name) {
+    const StringCRef &name) {
   Column *column = table_->find_column(error, name);
   if (!column) {
     return nullptr;
@@ -3954,7 +3954,7 @@ bool ExpressionBuilder::push_score(Error *error) {
   return builders_.back()->push_score(error);
 }
 
-bool ExpressionBuilder::push_column(Error *error, String name) {
+bool ExpressionBuilder::push_column(Error *error, const StringCRef &name) {
   return builders_.back()->push_column(error, name);
 }
 

  Modified: lib/grnxx/index.cpp (+7 -7)
===================================================================
--- lib/grnxx/index.cpp    2014-09-26 13:39:18 +0900 (2eaa60e)
+++ lib/grnxx/index.cpp    2014-09-26 14:27:14 +0900 (e6d92da)
@@ -51,7 +51,7 @@ Index::Index()
 
 bool Index::initialize_base(Error *error,
                             Column *column,
-                            String name,
+                            const StringCRef &name,
                             IndexType type,
                             const IndexOptions &) {
   column_ = column;
@@ -64,7 +64,7 @@ bool Index::initialize_base(Error *error,
 
 unique_ptr<Index> Index::create(Error *error,
                                 Column *column,
-                                String name,
+                                const StringCRef &name,
                                 IndexType type,
                                 const IndexOptions &options) {
   if (type != TREE_INDEX) {
@@ -100,7 +100,7 @@ unique_ptr<Index> Index::create(Error *error,
   }
 }
 
-bool Index::rename(Error *error, String new_name) {
+bool Index::rename(Error *error, const StringCRef &new_name) {
   return name_.assign(error, new_name);
 }
 
@@ -420,7 +420,7 @@ CursorResult ArrayCursor::read(Error *, ArrayRef<Record> records) {
 unique_ptr<TreeIndex<Bool>> TreeIndex<Bool>::create(
     Error *error,
     Column *column,
-    String name,
+    const StringCRef &name,
     const IndexOptions &options) {
   unique_ptr<TreeIndex> index(new (nothrow) TreeIndex);
   if (!index) {
@@ -578,7 +578,7 @@ bool TreeIndex<Bool>::remove(Error *, Int row_id, const Datum &value) {
 unique_ptr<TreeIndex<Int>> TreeIndex<Int>::create(
     Error *error,
     Column *column,
-    String name,
+    const StringCRef &name,
     const IndexOptions &options) {
   unique_ptr<TreeIndex> index(new (nothrow) TreeIndex);
   if (!index) {
@@ -736,7 +736,7 @@ bool TreeIndex<Int>::remove(Error *, Int row_id, const Datum &value) {
 unique_ptr<TreeIndex<Float>> TreeIndex<Float>::create(
     Error *error,
     Column *column,
-    String name,
+    const StringCRef &name,
     const IndexOptions &options) {
   unique_ptr<TreeIndex> index(new (nothrow) TreeIndex);
   if (!index) {
@@ -905,7 +905,7 @@ bool TreeIndex<Float>::remove(Error *, Int row_id, const Datum &value) {
 unique_ptr<TreeIndex<Text>> TreeIndex<Text>::create(
     Error *error,
     Column *column,
-    String name,
+    const StringCRef &name,
     const IndexOptions &options) {
   unique_ptr<TreeIndex> index(new (nothrow) TreeIndex);
   if (!index) {

  Modified: lib/grnxx/name.cpp (+2 -2)
===================================================================
--- lib/grnxx/name.cpp    2014-09-26 13:39:18 +0900 (5914f66)
+++ lib/grnxx/name.cpp    2014-09-26 14:27:14 +0900 (cddf6ca)
@@ -17,7 +17,7 @@ bool is_allowed_symbol(int c) {
 
 }  // namespace
 
-bool Name::assign(Error *error, String name) {
+bool Name::assign(Error *error, const StringCRef &name) {
   if (!test(error, name)) {
     return false;
   }
@@ -36,7 +36,7 @@ bool Name::assign(Error *error, String name) {
   return true;
 }
 
-bool Name::test(Error *error, String name) {
+bool Name::test(Error *error, const StringCRef &name) {
   if ((name.size() < MIN_SIZE) || (name.size() > MAX_SIZE)) {
     GRNXX_ERROR_SET(error, INVALID_NAME,
                     "Invalid name size: size = %" PRIi64, name.size());

  Modified: lib/grnxx/name.hpp (+4 -4)
===================================================================
--- lib/grnxx/name.hpp    2014-09-26 13:39:18 +0900 (8c31be4)
+++ lib/grnxx/name.hpp    2014-09-26 14:27:14 +0900 (b1033e5)
@@ -24,8 +24,8 @@ class Name {
   }
 
   // Return a reference to the name string.
-  String ref() const {
-    return String(data_.get(), size_);
+  StringCRef ref() const {
+    return StringCRef(data_.get(), size_);
   }
 
   // Assign a new name.
@@ -38,7 +38,7 @@ class Name {
   // Returns true on success.
   // On failure, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  bool assign(Error *error, String name);
+  bool assign(Error *error, const StringCRef &name);
 
  private:
   unique_ptr<char[]> data_;
@@ -52,7 +52,7 @@ class Name {
   // Returns true if "name" is valid.
   // Otherwise, returns false and stores error information into "*error" if
   // "error" != nullptr.
-  static bool test(Error *error, String name);
+  static bool test(Error *error, const StringCRef &name);
 };
 
 }  // namespace grnxx

  Modified: lib/grnxx/table.cpp (+11 -11)
===================================================================
--- lib/grnxx/table.cpp    2014-09-26 13:39:18 +0900 (dc8b4c1)
+++ lib/grnxx/table.cpp    2014-09-26 14:27:14 +0900 (5380ae8)
@@ -211,7 +211,7 @@ CursorResult TableCursor::reverse_read(Error *, ArrayRef<Record> records) {
 Table::~Table() {}
 
 Column *Table::create_column(Error *error,
-                             String name,
+                             const StringCRef &name,
                              DataType data_type,
                              const ColumnOptions &options) {
   if (find_column(nullptr, name)) {
@@ -232,7 +232,7 @@ Column *Table::create_column(Error *error,
   return columns_.back().get();
 }
 
-bool Table::remove_column(Error *error, String name) {
+bool Table::remove_column(Error *error, const StringCRef &name) {
   Int column_id;
   if (!find_column_with_id(error, name, &column_id)) {
     return false;
@@ -252,8 +252,8 @@ bool Table::remove_column(Error *error, String name) {
 }
 
 bool Table::rename_column(Error *error,
-                          String name,
-                          String new_name) {
+                          const StringCRef &name,
+                          const StringCRef &new_name) {
   Int column_id;
   if (!find_column_with_id(error, name, &column_id)) {
     return false;
@@ -271,8 +271,8 @@ bool Table::rename_column(Error *error,
 }
 
 bool Table::reorder_column(Error *error,
-                           String name,
-                           String prev_name) {
+                           const StringCRef &name,
+                           const StringCRef &prev_name) {
   Int column_id;
   if (!find_column_with_id(error, name, &column_id)) {
     return false;
@@ -298,7 +298,7 @@ bool Table::reorder_column(Error *error,
   return true;
 }
 
-Column *Table::find_column(Error *error, String name) const {
+Column *Table::find_column(Error *error, const StringCRef &name) const {
   for (Int column_id = 0; column_id < num_columns(); ++column_id) {
     if (name == columns_[column_id]->name()) {
       return columns_[column_id].get();
@@ -309,7 +309,7 @@ Column *Table::find_column(Error *error, String name) const {
   return nullptr;
 }
 
-bool Table::set_key_column(Error *error, String) {
+bool Table::set_key_column(Error *error, const StringCRef &) {
   if (key_column_) {
     GRNXX_ERROR_SET(error, ALREADY_EXISTS, "Key column already exists");
     return false;
@@ -465,7 +465,7 @@ unique_ptr<Cursor> Table::create_cursor(
 
 unique_ptr<Table> Table::create(Error *error,
                                 DB *db,
-                                String name,
+                                const StringCRef &name,
                                 const TableOptions &) {
   unique_ptr<Table> table(new Table);
   table->db_ = db;
@@ -569,7 +569,7 @@ bool Table::reserve_bit(Error *error, Int i) {
   return true;
 }
 
-bool Table::rename(Error *error, String new_name) {
+bool Table::rename(Error *error, const StringCRef &new_name) {
   return name_.assign(error, new_name);
 }
 
@@ -579,7 +579,7 @@ bool Table::is_removable() {
 }
 
 Column *Table::find_column_with_id(Error *error,
-                                   String name,
+                                   const StringCRef &name,
                                    Int *column_id) const {
   for (Int i = 0; i < num_columns(); ++i) {
     if (name == columns_[i]->name()) {

  Modified: lib/grnxx/tree_index.hpp (+4 -4)
===================================================================
--- lib/grnxx/tree_index.hpp    2014-09-26 13:39:18 +0900 (a32a32f)
+++ lib/grnxx/tree_index.hpp    2014-09-26 14:27:14 +0900 (499e272)
@@ -22,7 +22,7 @@ class TreeIndex<Bool> : public Index {
 
   static unique_ptr<TreeIndex> create(Error *error,
                                       Column *column,
-                                      String name,
+                                      const StringCRef &name,
                                       const IndexOptions &options);
 
   ~TreeIndex();
@@ -56,7 +56,7 @@ class TreeIndex<Int> : public Index {
 
   static unique_ptr<TreeIndex> create(Error *error,
                                       Column *column,
-                                      String name,
+                                      const StringCRef &name,
                                       const IndexOptions &options);
 
   ~TreeIndex();
@@ -102,7 +102,7 @@ class TreeIndex<Float> : public Index {
 
   static unique_ptr<TreeIndex> create(Error *error,
                                       Column *column,
-                                      String name,
+                                      const StringCRef &name,
                                       const IndexOptions &options);
 
   ~TreeIndex();
@@ -136,7 +136,7 @@ class TreeIndex<Text> : public Index {
 
   static unique_ptr<TreeIndex> create(Error *error,
                                       Column *column,
-                                      String name,
+                                      const StringCRef &name,
                                       const IndexOptions &options);
 
   ~TreeIndex();

  Modified: test/test_expression.cpp (+1 -1)
===================================================================
--- test/test_expression.cpp    2014-09-26 13:39:18 +0900 (038b111)
+++ test/test_expression.cpp    2014-09-26 14:27:14 +0900 (d6ae63e)
@@ -2702,7 +2702,7 @@ void test_subscript() {
     if (int_value < text_vector_value.size()) {
       assert(text_results[i] == text_vector_value[int_value]);
     } else {
-      assert(text_results[i] == 0);
+      assert(text_results[i] == grnxx::StringCRef(""));
     }
   }
 }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index