All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cody P Schafer <dev@codyps.com>
To: ccan@lists.ozlabs.org
Cc: Cody P Schafer <dev@codyps.com>
Subject: [PATCH v4 2/4] bytestring: use newly added mem helpers
Date: Sat,  5 Sep 2015 21:21:04 -0400	[thread overview]
Message-ID: <1441502466-4754-3-git-send-email-dev@codyps.com> (raw)
In-Reply-To: <1441502466-4754-1-git-send-email-dev@codyps.com>

Reviwed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Cody P Schafer <dev@codyps.com>
---
 ccan/bytestring/bytestring.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h
index dd1f913..bc99e79 100644
--- a/ccan/bytestring/bytestring.h
+++ b/ccan/bytestring/bytestring.h
@@ -94,8 +94,7 @@ static inline struct bytestring bytestring_from_string(const char *s)
  */
 static inline bool bytestring_eq(struct bytestring a, struct bytestring b)
 {
-	return (a.len == b.len)
-		&& (memcmp(a.ptr, b.ptr, a.len) == 0);
+	return memeq(a.ptr, a.len, b.ptr, b.len);
 }
 
 /**
@@ -149,8 +148,7 @@ static inline struct bytestring bytestring_slice(struct bytestring s,
 static inline bool bytestring_starts(struct bytestring s,
 				     struct bytestring prefix)
 {
-	return (s.len >= prefix.len) && (memcmp(s.ptr,
-						prefix.ptr, prefix.len) == 0);
+	return memstarts(s.ptr, s.len, prefix.ptr, prefix.len);
 }
 
 /**
@@ -163,8 +161,7 @@ static inline bool bytestring_starts(struct bytestring s,
 static inline bool bytestring_ends(struct bytestring s,
 				   struct bytestring suffix)
 {
-	return (s.len >= suffix.len) && (memcmp(s.ptr + s.len - suffix.len,
-						suffix.ptr, suffix.len) == 0);
+	return memends(s.ptr, s.len, suffix.ptr, suffix.len);
 }
 
 /**
-- 
2.5.1

_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

  parent reply	other threads:[~2015-09-06  1:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-06  1:21 [PATCH v4 0/4] mem: extend with a few additional helpers similar to existing string-only functions Cody P Schafer
2015-09-06  1:21 ` [PATCH v4 1/4] mem: add mem helper functions Cody P Schafer
2015-09-06  1:21 ` Cody P Schafer [this message]
2015-09-06  1:21 ` [PATCH v4 3/4] mem: mark all functions as PURE Cody P Schafer
2015-09-06  1:21 ` [PATCH v4 4/4] mem: add memends_str() helper for symmetry Cody P Schafer
2015-09-06 14:24 ` [PATCH v4 0/4] mem: extend with a few additional helpers similar to existing string-only functions David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441502466-4754-3-git-send-email-dev@codyps.com \
    --to=dev@codyps.com \
    --cc=ccan@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.