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

[PATCH 2/6] create_snapshot(): use `xmemdupz()` rather than a strbuf

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jan 24, 2018, 11:14 UTC
Message-ID
<612a0b909d1f73bb706e9c44a6e1d737f3a2bf95.1516791909.git.mhagger@alum.mit.edu>
In-Reply-To
<cea5e366-dc95-6f41-6373-f8bbef103561@alum.mit.edu>
It's lighter weight.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs/packed-backend.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index b872267f02..08698de6ea 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -620,8 +620,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
 
 	/* If the file has a header line, process it: */
 	if (snapshot->buf < snapshot->eof && *snapshot->buf == '#') {
-		struct strbuf tmp = STRBUF_INIT;
-		char *p, *eol;
+		char *tmp, *p, *eol;
 		struct string_list traits = STRING_LIST_INIT_NODUP;
 
 		eol = memchr(snapshot->buf, '\n',
@@ -631,9 +630,9 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
 					      snapshot->buf,
 					      snapshot->eof - snapshot->buf);
 
-		strbuf_add(&tmp, snapshot->buf, eol - snapshot->buf);
+		tmp = xmemdupz(snapshot->buf, eol - snapshot->buf);
 
-		if (!skip_prefix(tmp.buf, "# pack-refs with:", (const char **)&p))
+		if (!skip_prefix(tmp, "# pack-refs with:", (const char **)&p))
 			die_invalid_line(refs->path,
 					 snapshot->buf,
 					 snapshot->eof - snapshot->buf);
@@ -653,7 +652,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
 		snapshot->start = eol + 1;
 
 		string_list_clear(&traits, 0);
-		strbuf_release(&tmp);
+		free(tmp);
 	}
 
 	verify_buffer_safe(snapshot);
-- 
2.14.2
Previous: Jeff KingNext: Michael Haggerty
Message 28 of 33 in “packed_ref_cache: don't use mmap() for small files”
  1. packed_ref_cache: don't use mmap() for small filesKim Gybels, Jan 13, 2018
  2. Johannes SchindelinJan 13, 2018
  3. packed_ref_cache: don't use mmap() for small filesKim Gybels, Jan 14, 2018
  4. 0/3 Supplements to "packed_ref_cache: don't use mmap() for small files"Michael Haggerty, Jan 15, 2018
  5. Johannes SchindelinJan 17, 2018
  6. Junio C HamanoJan 17, 2018
  7. 1/3 SQUASH? Mention that `snapshot::buf` can be NULL for empty filesMichael Haggerty, Jan 15, 2018
  8. 2/3 create_snapshot(): exit early if the file was emptyMichael Haggerty, Jan 15, 2018
  9. 3/3 find_reference_location(): don't invoke if `snapshot->buf` is NULLMichael Haggerty, Jan 15, 2018
  10. Jeff KingJan 15, 2018
  11. Kim GybelsJan 15, 2018
  12. Jeff KingJan 15, 2018
  13. packed_ref_cache: don't use mmap() for small filesKim Gybels, Jan 16, 2018
  14. Jeff KingJan 17, 2018
  15. Michael HaggertyJan 21, 2018
  16. Junio C HamanoJan 22, 2018
  17. Michael HaggertyJan 24, 2018
  18. 0/6 Yet another approach to handling empty snapshotsMichael Haggerty, Jan 24, 2018
  19. Jeff KingJan 24, 2018
  20. Junio C HamanoJan 24, 2018
  21. Johannes SchindelinFeb 15, 2018
  22. 1/6 struct snapshot: store `start` rather than `header_len`Michael Haggerty, Jan 24, 2018
  23. Jeff KingJan 24, 2018
  24. 3/6 find_reference_location(): make function safe for empty snapshotsMichael Haggerty, Jan 24, 2018
  25. Jeff KingJan 24, 2018
  26. Junio C HamanoJan 24, 2018
  27. Jeff KingJan 24, 2018
  28. 2/6 create_snapshot(): use `xmemdupz()` rather than a strbufMichael Haggerty, Jan 24, 2018
  29. 5/6 load_contents(): don't try to mmap an empty fileMichael Haggerty, Jan 24, 2018
  30. 4/6 packed_ref_iterator_begin(): make optimization more generalMichael Haggerty, Jan 24, 2018
  31. Jeff KingJan 24, 2018
  32. 6/6 packed_ref_cache: don't use mmap() for small filesMichael Haggerty, Jan 24, 2018
  33. Junio C HamanoJan 24, 2018

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.