git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2.5/4] diff: avoid returning a struct by value from diff_flags_or()

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 31, 2017, 05:23 UTC
Message-ID
<xmqqo9on28mf.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20171030194646.27473-3-bmwill@google.com>

That is more in line with the design decision made in the previous step to pass struct by reference.

We may want to squash this into the previous patch eventually.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I am OK either way as long as things are consistent; as you took
   time to change the code to pass the struct by reference, let's
   unify the API in that direction.
 diff-lib.c |  2 +-
 diff.h     | 12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index 6c1c05c5b0..ed37f24c68 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -547,7 +547,7 @@ int index_differs_from(const char *def, const struct diff_flags *flags,
 	DIFF_OPT_SET(&rev.diffopt, QUICK);
 	DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
 	if (flags)
-		rev.diffopt.flags = diff_flags_or(&rev.diffopt.flags, flags);
+		diff_flags_or(&rev.diffopt.flags, flags);
 	rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
 	run_diff_index(&rev, 1);
 	object_array_clear(&rev.pending);
diff --git a/diff.h b/diff.h
index 47e6d43cbc..e512cf44d0 100644
--- a/diff.h
+++ b/diff.h
@@ -94,19 +94,15 @@ struct diff_flags {
 	unsigned DEFAULT_FOLLOW_RENAMES:1;
 };
 
-static inline struct diff_flags diff_flags_or(const struct diff_flags *a,
-					      const struct diff_flags *b)
+static inline void diff_flags_or(struct diff_flags *a,
+				 const struct diff_flags *b)
 {
-	struct diff_flags out;
 	char *tmp_a = (char *)a;
-	char *tmp_b = (char *)b;
-	char *tmp_out = (char *)&out;
+	const char *tmp_b = (const char *)b;
 	int i;
 
 	for (i = 0; i < sizeof(struct diff_flags); i++)
-		tmp_out[i] = tmp_a[i] | tmp_b[i];
-
-	return out;
+		tmp_a[i] |= tmp_b[i];
 }
 
 #define DIFF_OPT_TST(opts, flag)	((opts)->flags.flag)
-- 
2.15.0-224-g5109123e6a
Previous: Junio C HamanoNext: Brandon Williams
Message 18 of 47 in “convert diff flags to be stored in a struct”
  1. 0/3 convert diff flags to be stored in a structBrandon Williams, Oct 27, 2017
  2. 1/3 add: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 27, 2017
  3. 2/3 reset: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 27, 2017
  4. Junio C HamanoOct 29, 2017
  5. Brandon WilliamsOct 30, 2017
  6. 3/3 diff: convert flags to be stored in bitfieldsBrandon Williams, Oct 27, 2017
  7. Junio C HamanoOct 29, 2017
  8. Junio C HamanoOct 30, 2017
  9. Brandon WilliamsOct 30, 2017
  10. Junio C HamanoOct 31, 2017
  11. Brandon WilliamsOct 30, 2017
  12. Junio C HamanoOct 29, 2017
  13. Stefan BellerOct 29, 2017
  14. 0/4 convert diff flags to be stored in a structBrandon Williams, Oct 30, 2017
  15. 1/4 add, reset: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 30, 2017
  16. 2/4 diff: convert flags to be stored in bitfieldsBrandon Williams, Oct 30, 2017
  17. Junio C HamanoOct 31, 2017
  18. 5/4 diff: avoid returning a struct by value from diff_flags_or()Junio C Hamano, Oct 31, 2017
  19. Brandon WilliamsOct 31, 2017
  20. 4/4 diff: remove touched flagsBrandon Williams, Oct 30, 2017
  21. 3/4 diff: add flag to indicate textconv was set via cmdlineBrandon Williams, Oct 30, 2017
  22. Stefan BellerOct 30, 2017
  23. Brandon WilliamsOct 30, 2017
  24. Brandon WilliamsOct 30, 2017
  25. Junio C HamanoOct 31, 2017
  26. 5/4 diff: set TEXTCONV_VIA_CMDLINE only when it is set to trueJunio C Hamano, Oct 31, 2017
  27. Brandon WilliamsOct 31, 2017
  28. 5/4 diff: remove DIFF_OPT_TST macroBrandon Williams, Oct 30, 2017
  29. 7/4 diff: remove DIFF_OPT_CLR macroBrandon Williams, Oct 30, 2017
  30. 6/4 diff: remove DIFF_OPT_SET macroBrandon Williams, Oct 30, 2017
  31. 8/4 diff: make struct diff_flags members lowercaseBrandon Williams, Oct 30, 2017
  32. 0/8 convert diff flags to be stored in a structBrandon Williams, Oct 31, 2017
  33. 1/8 add, reset: use DIFF_OPT_SET macro to set a diff flagBrandon Williams, Oct 31, 2017
  34. 2/8 diff: convert flags to be stored in bitfieldsBrandon Williams, Oct 31, 2017
  35. Stefan BellerOct 31, 2017
  36. Junio C HamanoNov 1, 2017
  37. Stefan BellerNov 1, 2017
  38. 4/8 diff: remove touched flagsBrandon Williams, Oct 31, 2017
  39. 5/8 diff: remove DIFF_OPT_TST macroBrandon Williams, Oct 31, 2017
  40. 3/8 diff: add flag to indicate textconv was set via cmdlineBrandon Williams, Oct 31, 2017
  41. 6/8 diff: remove DIFF_OPT_SET macroBrandon Williams, Oct 31, 2017
  42. 7/8 diff: remove DIFF_OPT_CLR macroBrandon Williams, Oct 31, 2017
  43. Stefan BellerOct 31, 2017
  44. Junio C HamanoNov 1, 2017
  45. 8/8 diff: make struct diff_flags members lowercaseBrandon Williams, Oct 31, 2017
  46. Stefan BellerOct 31, 2017
  47. Junio C HamanoNov 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.