[ostree] core: Add API to convert csum -> checksum without malloc()
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Add API to convert csum -> checksum without malloc()
- Date: Sat, 23 Feb 2013 16:15:48 +0000 (UTC)
commit a821420711279415a41e17f559b1db8cab4fa275
Author: Colin Walters <walters verbum org>
Date: Sat Feb 23 11:02:56 2013 -0500
core: Add API to convert csum -> checksum without malloc()
Just doing some profiling, this was in the top malloc() callers.
src/libostree/ostree-core.c | 20 ++++++++++++--------
src/libostree/ostree-core.h | 3 +++
src/libostree/ostree-repo-file.c | 10 +++++-----
3 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 09ce530..9a90da5 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -948,23 +948,27 @@ ostree_checksum_to_bytes_v (const char *checksum)
return ot_gvariant_new_bytearray ((guchar*)result, 32);
}
-char *
-ostree_checksum_from_bytes (const guchar *csum)
+void
+ostree_checksum_inplace_from_bytes (const guchar *csum,
+ char *buf)
{
static const gchar hexchars[] = "0123456789abcdef";
- char *ret;
guint i, j;
- ret = g_malloc (65);
-
for (i = 0, j = 0; i < 32; i++, j += 2)
{
guchar byte = csum[i];
- ret[j] = hexchars[byte >> 4];
- ret[j+1] = hexchars[byte & 0xF];
+ buf[j] = hexchars[byte >> 4];
+ buf[j+1] = hexchars[byte & 0xF];
}
- ret[j] = '\0';
+ buf[j] = '\0';
+}
+char *
+ostree_checksum_from_bytes (const guchar *csum)
+{
+ char *ret = g_malloc (65);
+ ostree_checksum_inplace_from_bytes (csum, ret);
return ret;
}
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index 83f688b..b3f761e 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -113,6 +113,9 @@ GVariant *ostree_checksum_to_bytes_v (const char *checksum);
char * ostree_checksum_from_bytes (const guchar *bytes);
char * ostree_checksum_from_bytes_v (GVariant *bytes);
+void ostree_checksum_inplace_from_bytes (const guchar *bytes,
+ char *buf);
+
const guchar *ostree_checksum_bytes_peek (GVariant *bytes);
int ostree_cmp_checksum_bytes (const guchar *a, const guchar *b);
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index 5a95afc..0fb3a63 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -816,7 +816,7 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
ot_lvariant GVariant *tree_child_metadata = NULL;
ot_lvariant GVariant *content_csum_v = NULL;
ot_lvariant GVariant *meta_csum_v = NULL;
- ot_lfree char *tmp_checksum = NULL;
+ char tmp_checksum[65];
GFileAttributeMatcher *matcher = NULL;
if (!ostree_repo_file_ensure_resolved (self, error))
@@ -833,8 +833,8 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
if (n < c)
{
g_variant_get_child (files_variant, n, "(&s ay)", &name, &content_csum_v);
- g_free (tmp_checksum);
- tmp_checksum = ostree_checksum_from_bytes_v (content_csum_v);
+ ostree_checksum_inplace_from_bytes (ostree_checksum_bytes_peek (content_csum_v),
+ tmp_checksum);
if (!ostree_repo_load_file (self->repo, tmp_checksum, NULL, &ret_info, NULL,
cancellable, error))
@@ -850,8 +850,8 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
{
g_variant_get_child (dirs_variant, n, "(&s ay@ay)",
&name, NULL, &meta_csum_v);
- g_free (tmp_checksum);
- tmp_checksum = ostree_checksum_from_bytes_v (meta_csum_v);
+ ostree_checksum_inplace_from_bytes (ostree_checksum_bytes_peek (meta_csum_v),
+ tmp_checksum);
if (!query_child_info_dir (self->repo, tmp_checksum,
matcher, flags, &ret_info,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]