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

Re: [PATCH] Teach git-apply about '-R'

From
Linus Torvalds <torvalds@osdl.org>
Date
Jul 28, 2006, 15:14 UTC
Message-ID
<Pine.LNX.4.64.0607280809550.4168@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.63.0607281213250.29667@wbgn013.biozentrum.uni-wuerzburg.de>
On Fri, 28 Jul 2006, Johannes Schindelin wrote:
>
> +/* a and b may not overlap! */
> +static void memswap(void *a, void *b, unsigned int len)
This is disgusting.
Especially since it's also slow as hell.
Show 9 quoted lines
> +		memswap(p->new_name, p->old_name, sizeof(char *));
> +		memswap(&p->new_mode, &p->old_mode, sizeof(unsigned int));
> +		memswap(&p->is_new, &p->is_delete, sizeof(int));
> +		memswap(&p->lines_added, &p->lines_deleted, sizeof(int));
> +		memswap(p->old_sha1_prefix, p->new_sha1_prefix, 41);
> +
> +		for (; frag; frag = frag->next) {
> +			memswap(&frag->newpos, &frag->oldpos, sizeof(int));
> +			memswap(&frag->newlines, &frag->oldlines, sizeof(int));

All but one of those are register sizes, so doing a horribly ugly "memswap()"to do them is truly nasty, when you could have done

	#define swap(a,b) myswap((a),(b),sizeof(a))
	#define myswap(a,b,size) do {		\
		unsigned char mytmp[size];	\
		memcpy(tmp, &a, size);		\
		memcpy(&a, &b, size);		\
		memcpy(&b, mytmp, size);	\
	} while (0)

and it would have worked MUCH more efficiently, since any sane compiler would immediately have noticed that you're doing word-sized copies, and optimized the hell out of it.

(Untested, of course).
		Linus
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 17 of 22 in “t7001: add test for git-mv dir1 dir2/”
  1. 1/2 t7001: add test for git-mv dir1 dir2/Johannes Schindelin, Jul 26, 2006
  2. Jon SmirlJul 26, 2006
  3. Junio C HamanoJul 26, 2006
  4. Jon SmirlJul 26, 2006
  5. Junio C HamanoJul 26, 2006
  6. Junio C HamanoJul 26, 2006
  7. Jon SmirlJul 26, 2006
  8. Johannes SchindelinJul 26, 2006
  9. Josef WeidendorferJul 26, 2006
  10. Junio C HamanoJul 26, 2006
  11. Petr BaudisJul 28, 2006
  12. Junio C HamanoJul 28, 2006
  13. Petr BaudisJul 28, 2006
  14. Junio C HamanoJul 28, 2006
  15. Petr BaudisJul 28, 2006
  16. Teach git-apply about '-R'Johannes Schindelin, Jul 28, 2006
  17. Linus TorvaldsJul 28, 2006
  18. Teach git-apply about '-R'Johannes Schindelin, Jul 28, 2006
  19. Junio C HamanoJul 28, 2006
  20. Johannes SchindelinJul 28, 2006
  21. Junio C HamanoJul 28, 2006
  22. Johannes SchindelinJul 28, 2006

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.