public inbox for ccan@ozlabs.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 3/4] mem: mark all functions as PURE
Date: Sat,  5 Sep 2015 21:21:05 -0400	[thread overview]
Message-ID: <1441502466-4754-4-git-send-email-dev@codyps.com> (raw)
In-Reply-To: <1441502466-4754-1-git-send-email-dev@codyps.com>

This might allow compilers that support the anotation to make better
choices when optimizing, and all these functions meet the requirements
for being marked pure.

Signed-off-by: Cody P Schafer <dev@codyps.com>
---
 ccan/mem/_info |  1 +
 ccan/mem/mem.h | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/ccan/mem/_info b/ccan/mem/_info
index 19b2228..6389e35 100644
--- a/ccan/mem/_info
+++ b/ccan/mem/_info
@@ -18,6 +18,7 @@ int main(int argc, char *argv[])
 		return 1;
 
 	if (strcmp(argv[1], "depends") == 0) {
+		printf("ccan/compiler");
 		return 0;
 	}
 
diff --git a/ccan/mem/mem.h b/ccan/mem/mem.h
index 89b16d4..8d6bba9 100644
--- a/ccan/mem/mem.h
+++ b/ccan/mem/mem.h
@@ -3,16 +3,19 @@
 #define CCAN_MEM_H
 
 #include "config.h"
+#include <ccan/compiler/compiler.h>
 
 #include <string.h>
 #include <stdbool.h>
 
 #if !HAVE_MEMMEM
+PURE_FUNCTION
 void *memmem(const void *haystack, size_t haystacklen,
 	     const void *needle, size_t needlelen);
 #endif
 
 #if !HAVE_MEMRCHR
+PURE_FUNCTION
 void *memrchr(const void *s, int c, size_t n);
 #endif
 
@@ -37,6 +40,7 @@ void *memrchr(const void *s, int c, size_t n);
  *	}
  *
  */
+PURE_FUNCTION
 void *mempbrkm(const void *data, size_t len, const void *accept, size_t accept_len);
 
 /**
@@ -57,6 +61,7 @@ void *mempbrkm(const void *data, size_t len, const void *accept, size_t accept_l
  *		printf("Nada\n");
  *	}
  */
+PURE_FUNCTION
 static inline char *mempbrk(const void *data, size_t len, const char *accept)
 {
 	return mempbrkm(data, len, accept, strlen(accept));
@@ -81,6 +86,7 @@ static inline char *mempbrk(const void *data, size_t len, const char *accept)
  *		printf("Found %c after trimming spaces\n", *r);
  *	}
  */
+PURE_FUNCTION
 void *memcchr(void const *data, int c, size_t data_len);
 
 /**
@@ -95,6 +101,7 @@ void *memcchr(void const *data, int c, size_t data_len);
  *		printf("memory blocks are the same!\n");
  *	}
  */
+PURE_FUNCTION
 static inline bool memeq(const void *a, size_t al, const void *b, size_t bl)
 {
 	return al == bl && !memcmp(a, b, bl);
@@ -114,6 +121,7 @@ static inline bool memeq(const void *a, size_t al, const void *b, size_t bl)
  *		printf("somebytes starts with otherbytes!\n");
  *	}
  */
+PURE_FUNCTION
 static inline bool memstarts(void const *data, size_t data_len,
 		void const *prefix, size_t prefix_len)
 {
@@ -135,6 +143,7 @@ static inline bool memstarts(void const *data, size_t data_len,
  *		printf("somebytes == 'foo'!\n");
  *	}
  */
+PURE_FUNCTION
 static inline bool memeqstr(const void *data, size_t length, const char *string)
 {
 	return memeq(data, length, string, strlen(string));
@@ -151,6 +160,7 @@ static inline bool memeqstr(const void *data, size_t length, const char *string)
  *		printf("somebytes starts with 'It'\n");
  *	}
  */
+PURE_FUNCTION
 static inline bool memstarts_str(const void *a, size_t al, const char *s)
 {
 	return memstarts(a, al, s, strlen(s));
@@ -166,6 +176,7 @@ static inline bool memstarts_str(const void *a, size_t al, const char *s)
  * Returns true if @suffix appears as a substring at the end of @s,
  * false otherwise.
  */
+PURE_FUNCTION
 static inline bool memends(const void *s, size_t s_len, const void *suffix, size_t suffix_len)
 {
 	return (s_len >= suffix_len) && (memcmp((const char *)s + s_len - 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 ` [PATCH v4 2/4] bytestring: use newly added mem helpers Cody P Schafer
2015-09-06  1:21 ` Cody P Schafer [this message]
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-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox