susumu.yata
null+****@clear*****
Fri Sep 26 15:52:17 JST 2014
susumu.yata 2014-09-26 15:52:17 +0900 (Fri, 26 Sep 2014) New Revision: 425530ae09d78e6c412d89d5adacf6853b6aec9a https://github.com/groonga/grnxx/commit/425530ae09d78e6c412d89d5adacf6853b6aec9a Message: Update ConstantNode to use String instead of std::string. (#75) Modified files: lib/grnxx/expression.cpp Modified: lib/grnxx/expression.cpp (+14 -10) =================================================================== --- lib/grnxx/expression.cpp 2014-09-26 15:46:28 +0900 (b79bce0) +++ lib/grnxx/expression.cpp 2014-09-26 15:52:17 +0900 (b68d1b2) @@ -331,16 +331,21 @@ class ConstantNode<Text> : public TypedNode<Text> { public: using Value = Text; - static unique_ptr<Node> create(Error *error, Value datum) try { - return unique_ptr<Node>(new ConstantNode(datum)); - } catch (...) { - GRNXX_ERROR_SET(error, NO_MEMORY, "Memory allocation failed"); - return nullptr; + static unique_ptr<Node> create(Error *error, Value datum) { + unique_ptr<ConstantNode> node(new (nothrow) ConstantNode); + if (!node) { + GRNXX_ERROR_SET(error, NO_MEMORY, "Memory allocation failed"); + return nullptr; + } + if (!node->datum_.assign(error, datum)) { + return nullptr; + } + return unique_ptr<Node>(node.release()); } - explicit ConstantNode(Value datum) + explicit ConstantNode() : TypedNode<Value>(), - datum_(datum.data(), datum.size()) {} + datum_() {} NodeType node_type() const { return CONSTANT_NODE; @@ -349,15 +354,14 @@ class ConstantNode<Text> : public TypedNode<Text> { bool evaluate(Error *, ArrayCRef<Record> records, ArrayRef<Value> results) { - Text datum(datum_.data(), datum_.size()); for (Int i = 0; i < records.size(); ++i) { - results[i] = datum; + results[i] = datum_; } return true; } private: - std::string datum_; + String datum_; }; template <> -------------- next part -------------- HTML����������������������������... Download