From: Jeff King Date: Mon, 30 Jun 2014 16:58:51 +0000 (-0400) Subject: use strip_suffix instead of ends_with in simple cases X-Git-Tag: v2.1.0-rc0~40^2~4 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/26936bfd9bde1ec46901bea3e53d4fb9ae1b4a4c?ds=inline;hp=26936bfd9bde1ec46901bea3e53d4fb9ae1b4a4c use strip_suffix instead of ends_with in simple cases When stripping a suffix like: if (ends_with(str, "foo")) buf = xmemdupz(str, strlen(str) - 3); we can instead use strip_suffix to avoid the constant 3, which must match the literal "foo" (we sometimes use strlen("foo") instead, but that means we are repeating ourselves). The example above becomes: if (strip_suffix(str, "foo", &len)) buf = xmemdupz(str, len); This also saves a strlen(), since we calculate the string length when detecting the suffix. Note that in some cases we also switch from xstrndup to xmemdupz, which saves a further strlen call. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano ---