From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/6] attr: remove the union in struct match_attr
Date: Thu, 4 Oct 2012 14:39:47 +0700 [thread overview]
Message-ID: <1349336392-1772-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1349336392-1772-1-git-send-email-pclouds@gmail.com>
We're going to add more attributes to u.pattern so it'll become bigger
in size than a pointer. There's no point in sharing the same room with
u.attr.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
attr.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/attr.c b/attr.c
index 15ebaa1..48df800 100644
--- a/attr.c
+++ b/attr.c
@@ -119,10 +119,10 @@ struct attr_state {
/*
* One rule, as from a .gitattributes file.
*
- * If is_macro is true, then u.attr is a pointer to the git_attr being
+ * If is_macro is true, then attr is a pointer to the git_attr being
* defined.
*
- * If is_macro is false, then u.pattern points at the filename pattern
+ * If is_macro is false, then pattern points at the filename pattern
* to which the rule applies. (The memory pointed to is part of the
* memory block allocated for the match_attr instance.)
*
@@ -131,10 +131,8 @@ struct attr_state {
* listed as they appear in the file (macros unexpanded).
*/
struct match_attr {
- union {
- char *pattern;
- struct git_attr *attr;
- } u;
+ const char *pattern;
+ struct git_attr *attr;
char is_macro;
unsigned num_attr;
struct attr_state state[FLEX_ARRAY];
@@ -240,11 +238,12 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
sizeof(struct attr_state) * num_attr +
(is_macro ? 0 : namelen + 1));
if (is_macro)
- res->u.attr = git_attr_internal(name, namelen);
+ res->attr = git_attr_internal(name, namelen);
else {
- res->u.pattern = (char *)&(res->state[num_attr]);
- memcpy(res->u.pattern, name, namelen);
- res->u.pattern[namelen] = 0;
+ char *p = (char *)&(res->state[num_attr]);
+ memcpy(p, name, namelen);
+ p[namelen] = 0;
+ res->pattern = p;
}
res->is_macro = is_macro;
res->num_attr = num_attr;
@@ -682,7 +681,7 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
if (*n == ATTR__UNKNOWN) {
debug_set(what,
- a->is_macro ? a->u.attr->name : a->u.pattern,
+ a->is_macro ? a->attr->name : a->pattern,
attr, v);
*n = v;
rem--;
@@ -702,7 +701,7 @@ static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
if (a->is_macro)
continue;
if (path_matches(path, pathlen,
- a->u.pattern, base, strlen(base)))
+ a->pattern, base, strlen(base)))
rem = fill_one("fill", a, rem);
}
return rem;
@@ -722,7 +721,7 @@ static int macroexpand_one(int attr_nr, int rem)
struct match_attr *ma = stk->attrs[i];
if (!ma->is_macro)
continue;
- if (ma->u.attr->attr_nr == attr_nr)
+ if (ma->attr->attr_nr == attr_nr)
a = ma;
}
--
1.7.12.1.405.gb727dc9
next prev parent reply other threads:[~2012-10-04 22:01 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-02 23:20 What's cooking in git.git (Oct 2012, #01; Tue, 2) Junio C Hamano
2012-10-03 15:23 ` Nguyen Thai Ngoc Duy
2012-10-03 18:17 ` Junio C Hamano
2012-10-04 1:56 ` Nguyen Thai Ngoc Duy
2012-10-04 6:01 ` Junio C Hamano
2012-10-04 7:39 ` [PATCH 0/6] wildmatch part 2 Nguyễn Thái Ngọc Duy
2012-10-04 7:39 ` Nguyễn Thái Ngọc Duy [this message]
2012-10-04 7:39 ` [PATCH 2/6] attr: avoid strlen() on every match Nguyễn Thái Ngọc Duy
2012-10-04 7:39 ` [PATCH 3/6] attr: avoid searching for basename " Nguyễn Thái Ngọc Duy
2012-10-04 7:39 ` [PATCH 4/6] attr: more matching optimizations from .gitignore Nguyễn Thái Ngọc Duy
2012-10-04 7:39 ` [PATCH 5/6] gitignore: do not do basename match with patterns that have '**' Nguyễn Thái Ngọc Duy
2012-10-04 17:59 ` Junio C Hamano
2012-10-05 7:01 ` Johannes Sixt
2012-10-05 11:23 ` Nguyen Thai Ngoc Duy
2012-10-04 7:39 ` [PATCH 6/6] t3001: note about expected "**" behavior Nguyễn Thái Ngọc Duy
2012-10-04 18:04 ` Junio C Hamano
2012-10-04 17:43 ` [PATCH 0/6] wildmatch part 2 Junio C Hamano
2012-10-04 9:34 ` What's cooking in git.git (Oct 2012, #01; Tue, 2) Michael Haggerty
2012-10-04 11:46 ` Nguyen Thai Ngoc Duy
2012-10-04 15:17 ` Michael Haggerty
2012-10-04 16:39 ` Junio C Hamano
2012-10-05 12:19 ` Andreas Schwab
2012-10-05 12:30 ` Matthieu Moy
2012-10-05 14:15 ` Andreas Schwab
2012-10-05 13:21 ` Nguyen Thai Ngoc Duy
2012-10-04 8:17 ` David Michael Barr
2012-10-04 8:30 ` fa/remote-svn (Re: What's cooking in git.git (Oct 2012, #01; Tue, 2)) Jonathan Nieder
2012-10-04 13:16 ` Stephen Bash
2012-10-04 16:30 ` Junio C Hamano
2012-10-04 16:27 ` What's cooking in git.git (Oct 2012, #01; Tue, 2) Junio C Hamano
2012-10-30 12:15 ` Florian Achleitner
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349336392-1772-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).