From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Riesen Subject: [PATCH 1/2] Add a string_list_foreach macro Date: Tue, 29 Jun 2010 10:35:15 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=0015174bed84d08e72048a271d43 Cc: Thiago Farina , git@vger.kernel.org, jrnieder@gmail.com, srabbelier@gmail.com To: Junio C Hamano X-From: git-owner@vger.kernel.org Tue Jun 29 10:35:36 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OTWHy-0001AR-Un for gcvg-git-2@lo.gmane.org; Tue, 29 Jun 2010 10:35:31 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754065Ab0F2IfW (ORCPT ); Tue, 29 Jun 2010 04:35:22 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:35749 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753534Ab0F2IfR (ORCPT ); Tue, 29 Jun 2010 04:35:17 -0400 Received: by ewy23 with SMTP id 23so287622ewy.19 for ; Tue, 29 Jun 2010 01:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:cc:content-type; bh=tmNvFzxkUPdxAB7fNm+MQRGlTFrBpACTS1/x9nk7GY8=; b=sQ0VHyVaVx3739Nutgz5RvnUqKZQDIrgMs15eJD1m5+k1TkeGvjMjkhJS1/XIheMVb ObpmvCrzrWNRy8akaPf6APvZqmObyfScubyxCmk8PtyJ4z8k4c6qTmnpammLlsJsLxPN AV8EQGjuaNZG1bMEgU6p7//fvH1TE/eUN0srY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=vZfh9LCS7i7Uud03X+zNi47Qg/uE2/EoLxlKzZonlthYe7h239udDlILHvLqCiA8zT 7eOVQN4O0pbJ++ti99UnR40AvYki70vhAFufGZf7vi3rLIXtzj6CRIht3T61Tj/ffVSC zguZNKXzwRQDUamz4T6DdoX6PwdjWjEmZUJ+U= Received: by 10.213.22.201 with SMTP id o9mr1587397ebb.89.1277800515407; Tue, 29 Jun 2010 01:35:15 -0700 (PDT) Received: by 10.213.105.148 with HTTP; Tue, 29 Jun 2010 01:35:15 -0700 (PDT) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: --0015174bed84d08e72048a271d43 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable This is more lightweight than for_each_string_list function with callback function and a cookie argument. Signed-off-by: Alex Riesen --- On Tue, Jun 29, 2010 at 10:33, Alex Riesen wrote: > BTW, now that I took a look at it... The iteration over string_list > items looks a little overengineered. At least from the point of > view of the existing users of the feature. Wouldn't a simple loop > be just as simple to use (if not simplier) and faster (no uninlineable > function calls and argument preparation and passing needed)? > > #define string_list_foreach(item,list) \ > =C2=A0 =C2=A0 =C2=A0 =C2=A0for (item =3D (list)->items; item < (list)->it= ems + (list)->nr; ++item) > string-list.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/string-list.h b/string-list.h index 63b69c8..188d087 100644 --- a/string-list.h +++ b/string-list.h @@ -24,6 +24,8 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c typedef int (*string_list_each_func_t)(struct string_list_item *, void *); int for_each_string_list(string_list_each_func_t, struct string_list *list, void *cb_data); +#define string_list_foreach(item,list) \ + for (item =3D (list)->items; item < (list)->items + (list)->nr; ++item) /* Use these functions only on sorted lists: */ int string_list_has_string(const struct string_list *list, const char *str= ing); --=20 1.7.1.622.g408a98 --0015174bed84d08e72048a271d43 Content-Type: application/octet-stream; name="0001-Add-a-string_list_foreach-macro.diff" Content-Disposition: attachment; filename="0001-Add-a-string_list_foreach-macro.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