tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] ANSHUMAN87 commented on a change in pull request #5806: [RUNTIME][String] Overload string operators
Date Tue, 16 Jun 2020 06:22:57 GMT

ANSHUMAN87 commented on a change in pull request #5806:
URL: https://github.com/apache/incubator-tvm/pull/5806#discussion_r440610437



##########
File path: include/tvm/runtime/container.h
##########
@@ -1410,10 +1369,107 @@ inline String& String::operator=(std::string other) {
 
 inline String& String::operator=(const char* other) { return operator=(std::string(other));
}
 
-inline String operator+(const std::string lhs, const String& rhs) {
-  return lhs + rhs.operator std::string();
+inline String operator+(const String& lhs, const String& rhs) {
+  size_t lhs_size = lhs.size();
+  size_t rhs_size = rhs.size();
+  char* concat = String::Concat(lhs.data(), lhs_size, rhs.data(), rhs_size);
+  return String(concat);
 }
 
+inline String operator+(const String& lhs, const std::string& rhs) {
+  size_t lhs_size = lhs.size();
+  size_t rhs_size = rhs.size();
+  char* concat = String::Concat(lhs.data(), lhs_size, rhs.data(), rhs_size);
+  return String(concat);
+}
+
+inline String operator+(const std::string& lhs, const String& rhs) {
+  size_t lhs_size = lhs.size();
+  size_t rhs_size = rhs.size();
+  char* concat = String::Concat(lhs.data(), lhs_size, rhs.data(), rhs_size);
+  return String(concat);
+}
+
+inline String operator+(const char* lhs, const String& rhs) {
+  size_t lhs_size = std::strlen(lhs);
+  size_t rhs_size = rhs.size();
+  char* concat = String::Concat(lhs, lhs_size, rhs.data(), rhs_size);
+  return String(concat);
+}
+
+inline String operator+(const String& lhs, const char* rhs) {
+  size_t lhs_size = lhs.size();
+  size_t rhs_size = std::strlen(rhs);
+  char* concat = String::Concat(lhs.data(), lhs_size, rhs, rhs_size);
+  return String(concat);
+}
+
+// Overload < operator
+inline bool operator<(const String& lhs, const std::string& rhs) { return lhs.compare(rhs)
< 0; }

Review comment:
       @zhiics : Thanks for the PR! The changes looks good to me. Great work:)
   
   One small suggestion(Not Important Though).
   May be we can use some Macro as below:
   OPERATOR_OVERLOAD_COMMUTATIVE(operator<, String, std::string)
   
   #define OPERATOR_OVERLOAD_COMMUTATIVE(OP, T1, T2)  \
   inline bool OP(const T1& lhs, const T2& rhs) { return lhs.compare(rhs) < 0;
}  \
   inline bool OP(const T2& lhs, const T1& rhs) { return rhs.compare(lhs) > 0;
}




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message