[
https://issues.apache.org/jira/browse/GEODE-3288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16282071#comment-16282071
]
ASF GitHub Bot commented on GEODE-3288:
---------------------------------------
dgkimura commented on a change in pull request #165: GEODE-3288: Converts
CacheableString to std::string.
URL: https://github.com/apache/geode-native/pull/165#discussion_r155346674
##########
File path: cppcache/include/geode/CacheableString.hpp
##########
@@ -238,53 +165,64 @@ class CPPCACHE_EXPORT CacheableString : public
CacheableKey {
virtual uint32_t objectSize() const override;
protected:
- /** Private method to populate the <code>CacheableString</code>. */
- void copyString(const char* value, int32_t len);
- /** Private method to populate the <code>CacheableString</code>. */
- void copyString(const wchar_t* value, int32_t len);
- /** initialize the string, given a value and length. */
+ /**
+ * initialize the string, given a value and length. Assumes UTF-8.
+ */
void initString(const char* value, int32_t len);
+
+ void initString(std::string&& value);
+
/**
- * Initialize the string without making a copy, given a C string
- * and length.
+ * initialize the string, given a wide-char string and length. Assumes
+ * UTF-16.
*/
- void initStringNoCopy(char* value, int32_t len);
- /** initialize the string, given a wide-char string and length. */
void initString(const wchar_t* value, int32_t len);
+
/**
* Initialize the string without making a copy, given a wide-char string
- * and length.
+ * and length. Assumes UTF-16.
*/
void initStringNoCopy(wchar_t* value, int32_t len);
- /** Private method to get ASCII string for wide-string if possible. */
- char* getASCIIString(const wchar_t* value, int32_t& len, int32_t&
encodedLen);
+
/** Default constructor. */
inline CacheableString(int8_t type = GF_STRING)
- : m_str(nullptr), m_type(type), m_len(0), m_hashcode(0) {}
+ : m_str(), m_type(type), m_hashcode(0) {}
+
+ inline CacheableString(const std::string& value)
+ : CacheableString(std::string(value)) {}
+
+ inline CacheableString(std::string&& value)
+ : m_str(std::move(value)), m_hashcode(0) {
+ bool ascii = isAscii(m_str);
+
+ m_type = m_str.length() > std::numeric_limits<uint16_t>::max()
+ ? ascii ? GF_STRING_HUGE : GF_WIDESTRING_HUGE
+ : ascii ? GF_STRING : GF_WIDESTRING;
+ }
private:
// never implemented.
void operator=(const CacheableString& other) = delete;
CacheableString(const CacheableString& other) = delete;
+
+ static bool isAscii(const std::string& str);
};
/** overload of apache::geode::client::createKeyArr to pass char* */
inline std::shared_ptr<CacheableKey> createKeyArr(const char* value) {
return CacheableString::create(value);
}
-/** overload of apache::geode::client::createKeyArr to pass wchar_t* */
-inline std::shared_ptr<CacheableKey> createKeyArr(const wchar_t* value) {
+inline std::shared_ptr<CacheableKey> createKeyArr(const std::string& value) {
return CacheableString::create(value);
}
-/** overload of apache::geode::client::createValueArr to pass char* */
-inline std::shared_ptr<Cacheable> createValueArr(const char* value) {
- return CacheableString::create(value);
+inline std::shared_ptr<CacheableKey> createKeyArr(std::string&& value) {
Review comment:
Another place we may be able to use universal ref and std::forward
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Replace char* with std::string
> ------------------------------
>
> Key: GEODE-3288
> URL: https://issues.apache.org/jira/browse/GEODE-3288
> Project: Geode
> Issue Type: Improvement
> Components: native client
> Reporter: Ernest Burghardt
>
> In all public API headers
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)