{"thread":{"id":"36014","subject":"[PATCH][GSoC] git-compat-util.h:rewrite skip_prefix() as loop","startedAt":"2014-03-01T22:42:11Z","lastAt":"2014-03-02T04:53:04Z","messageCount":2,"participants":["kgeorgiou","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"235764","messageId":"1393713731-55358-1-git-send-email-kyriakos.a.georgiou@gmail.com","threadId":"36014","inReplyTo":null,"subject":"[PATCH][GSoC] git-compat-util.h:rewrite skip_prefix() as loop","fromName":"kgeorgiou","fromEmail":"kyriakos.a.georgiou@gmail.com","sentAt":"2014-03-01T22:42:11Z","receivedAt":"2014-03-01T22:42:11Z","isPatch":true,"sender":{"key":"kyriakos.a.georgiou@gmail.com","avatar":null},"body":"Rewritten git-compat-util.h:skip_prefix() as a loop, so that it doesn't have to\nscan through the prefix string twice as a miniproject for GSoC 2014.\n\n(I've just noticed that this miniproject has already been tackled by another \ncontributor, if that's a problem I can pick something else.)\n\nLooking forward to any kind of feedback.\n\n- Kyriakos Georgiou\n\nSigned-off-by: kgeorgiou <kyriakos.a.georgiou@gmail.com>\n---\n git-compat-util.h | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 614a5e9..713f37a 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -357,8 +357,11 @@ extern int suffixcmp(const char *str, const char *suffix);\n \n static inline const char *skip_prefix(const char *str, const char *prefix)\n {\n-\tsize_t len = strlen(prefix);\n-\treturn strncmp(str, prefix, len) ? NULL : str + len;\n+\twhile(*prefix && *str == *prefix) {\n+\t\tstr++;\n+\t\tprefix++;\n+\t}\n+\treturn *prefix ? NULL : str;\n }\n \n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n-- \n1.8.3.2\n"},{"id":"235781","messageId":"CAPig+cRFbk8CzXrHrDgjweevns8+AJ+FuWZVa8zphwHz16=8Jg@mail.gmail.com","threadId":"36014","inReplyTo":"1393713731-55358-1-git-send-email-kyriakos.a.georgiou@gmail.com","subject":"Re: [PATCH][GSoC] git-compat-util.h:rewrite skip_prefix() as loop","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-02T04:53:04Z","receivedAt":"2014-03-02T04:53:04Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"Thanks for the submission. Minor comments below to give you a taste of\nwhat it's like to contribute to this project...\n\nOn Sat, Mar 1, 2014 at 5:42 PM, kgeorgiou <kyriakos.a.georgiou@gmail.com> wrote:\n> Subject: git-compat-util.h:rewrite skip_prefix() as loop\n\nSpace after colon. You might be able to provide more information in\nthe short summary of the subject. Perhaps something like this:\n\n    Subject: skip_prefix(): avoid scanning 'prefix' twice\n\n> Rewritten git-compat-util.h:skip_prefix() as a loop, so that it doesn't have to\n> scan through the prefix string twice as a miniproject for GSoC 2014.\n\nGood description. In this project, use imperative tone:\n\n    Rewrite skip_prefix() as loop...\n\n> (I've just noticed that this miniproject has already been tackled by another\n> contributor, if that's a problem I can pick something else.)\n\nThat's okay. The purpose of the miniprojects is for you to get a taste\nof what it's like to contribute to this project and to understand what\nwill be expected of you as a GSoC student; and to give the GSoC\nmentors a chance to judge your abilities and observe how you interact\nwith reviewers.\n\n> Looking forward to any kind of feedback.\n>\n> - Kyriakos Georgiou\n\nThere are two types of information you want to convey to readers. (1)\nPatch description, explanation, justification before the \"---\" line\nwhich is recorded in the permanent project history. (2) Commentary\nbelow the \"---\" line for readers of the patch but not of interest once\nthe patch is accepted officially. The \"as a miniproject for GSoC\" and\nall lines following it are just commentary which should go below the\n\"---\" line.\n\n> Signed-off-by: kgeorgiou <kyriakos.a.georgiou@gmail.com>\n\nThis project prefers real names, so:\n\n    Signed-off-by: Kyriakos Georgiou <...>\n\n> ---\n>  git-compat-util.h | 7 +++++--\n>  1 file changed, 5 insertions(+), 2 deletions(-)\n>\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 614a5e9..713f37a 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -357,8 +357,11 @@ extern int suffixcmp(const char *str, const char *suffix);\n>\n>  static inline const char *skip_prefix(const char *str, const char *prefix)\n>  {\n> -       size_t len = strlen(prefix);\n> -       return strncmp(str, prefix, len) ? NULL : str + len;\n> +       while(*prefix && *str == *prefix) {\n\nStyle nit: space after 'while'.\n\n> +               str++;\n> +               prefix++;\n> +       }\n> +       return *prefix ? NULL : str;\n>  }\n>\n>  #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n> --\n> 1.8.3.2\n"}]}