You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2021/06/16 21:53:29 UTC

[trafficserver] branch 9.1.x updated: Add overload for memcpy to take a destination buffer and source string_view / TextView (#7732)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.1.x by this push:
     new 035b796  Add overload for memcpy to take a destination buffer and source string_view / TextView (#7732)
035b796 is described below

commit 035b796e589157cd5eb41e0f54d467c1e0a82dd3
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Mon Apr 26 16:14:26 2021 -0500

    Add overload for memcpy to take a destination buffer and source string_view / TextView (#7732)
    
    (cherry picked from commit 4d85f1c1022bb2f1e738cdc0b392187cc9e3517b)
---
 include/tscpp/util/TextView.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/include/tscpp/util/TextView.h b/include/tscpp/util/TextView.h
index b3b1eff..6a4754f 100644
--- a/include/tscpp/util/TextView.h
+++ b/include/tscpp/util/TextView.h
@@ -65,6 +65,29 @@ int strcasecmp(const std::string_view &lhs, const std::string_view &rhs);
  */
 int memcmp(const std::string_view &lhs, const std::string_view &rhs);
 
+/** Copy bytes.
+ *
+ * @param dst Destination buffer.
+ * @param src Original string.
+ * @return @a dest
+ *
+ * This is a convenience for
+ * @code
+ *   memcpy(dst, src.data(), size.size());
+ * @endcode
+ * Therefore @a dst must point at a buffer large enought to hold @a src. If this is not already
+ * determined, then presuming @c DST_SIZE is the size of the buffer at @a dst
+ * @code
+ *   memcpy(dst, src.prefix(DST_SIZE));
+ * @endcode
+ *
+ */
+inline void *
+memcpy(void *dst, const std::string_view &src)
+{
+  return memcpy(dst, src.data(), src.size());
+}
+
 /** Compare views with ordering.
  *
  * @param lhs input view