mirror of
https://github.com/git/git.git
synced 2026-08-05 07:31:02 +00:00
reftable/record: convert old and new object IDs to arrays
In7af607c58d(reftable/record: store "val1" hashes as static arrays, 2024-01-03) andb31e3cc620(reftable/record: store "val2" hashes as static arrays, 2024-01-03) we have converted ref records to store their object IDs in a static array. Convert log records to do the same so that their old and new object IDs are arrays, too. This change results in two allocations less per log record that we're iterating over. Before: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 8,068,495 allocs, 8,068,373 frees, 401,011,862 bytes allocated After: HEAP SUMMARY: in use at exit: 13,473 bytes in 122 blocks total heap usage: 6,068,489 allocs, 6,068,367 frees, 361,011,822 bytes allocated Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
eea0d11d6d
commit
87ff723018
@@ -171,23 +171,6 @@ static int should_write_log(struct ref_store *refs, const char *refname)
|
||||
}
|
||||
}
|
||||
|
||||
static void clear_reftable_log_record(struct reftable_log_record *log)
|
||||
{
|
||||
switch (log->value_type) {
|
||||
case REFTABLE_LOG_UPDATE:
|
||||
/*
|
||||
* When we write log records, the hashes are owned by the
|
||||
* caller and thus shouldn't be free'd.
|
||||
*/
|
||||
log->value.update.old_hash = NULL;
|
||||
log->value.update.new_hash = NULL;
|
||||
break;
|
||||
case REFTABLE_LOG_DELETION:
|
||||
break;
|
||||
}
|
||||
reftable_log_record_release(log);
|
||||
}
|
||||
|
||||
static void fill_reftable_log_record(struct reftable_log_record *log)
|
||||
{
|
||||
const char *info = git_committer_info(0);
|
||||
@@ -1102,8 +1085,8 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
|
||||
fill_reftable_log_record(log);
|
||||
log->update_index = ts;
|
||||
log->refname = xstrdup(u->refname);
|
||||
log->value.update.new_hash = u->new_oid.hash;
|
||||
log->value.update.old_hash = tx_update->current_oid.hash;
|
||||
memcpy(log->value.update.new_hash, u->new_oid.hash, GIT_MAX_RAWSZ);
|
||||
memcpy(log->value.update.old_hash, tx_update->current_oid.hash, GIT_MAX_RAWSZ);
|
||||
log->value.update.message =
|
||||
xstrndup(u->msg, arg->refs->write_options.block_size / 2);
|
||||
}
|
||||
@@ -1158,7 +1141,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
|
||||
done:
|
||||
assert(ret != REFTABLE_API_ERROR);
|
||||
for (i = 0; i < logs_nr; i++)
|
||||
clear_reftable_log_record(&logs[i]);
|
||||
reftable_log_record_release(&logs[i]);
|
||||
free(logs);
|
||||
return ret;
|
||||
}
|
||||
@@ -1275,13 +1258,13 @@ static int write_create_symref_table(struct reftable_writer *writer, void *cb_da
|
||||
log.update_index = ts;
|
||||
log.value.update.message = xstrndup(create->logmsg,
|
||||
create->refs->write_options.block_size / 2);
|
||||
log.value.update.new_hash = new_oid.hash;
|
||||
memcpy(log.value.update.new_hash, new_oid.hash, GIT_MAX_RAWSZ);
|
||||
if (refs_resolve_ref_unsafe(&create->refs->base, create->refname,
|
||||
RESOLVE_REF_READING, &old_oid, NULL))
|
||||
log.value.update.old_hash = old_oid.hash;
|
||||
memcpy(log.value.update.old_hash, old_oid.hash, GIT_MAX_RAWSZ);
|
||||
|
||||
ret = reftable_writer_add_log(writer, &log);
|
||||
clear_reftable_log_record(&log);
|
||||
reftable_log_record_release(&log);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1420,7 +1403,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
|
||||
logs[logs_nr].update_index = deletion_ts;
|
||||
logs[logs_nr].value.update.message =
|
||||
xstrndup(arg->logmsg, arg->refs->write_options.block_size / 2);
|
||||
logs[logs_nr].value.update.old_hash = old_ref.value.val1;
|
||||
memcpy(logs[logs_nr].value.update.old_hash, old_ref.value.val1, GIT_MAX_RAWSZ);
|
||||
logs_nr++;
|
||||
|
||||
ret = read_ref_without_reload(arg->stack, "HEAD", &head_oid, &head_referent, &head_type);
|
||||
@@ -1452,7 +1435,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
|
||||
logs[logs_nr].update_index = creation_ts;
|
||||
logs[logs_nr].value.update.message =
|
||||
xstrndup(arg->logmsg, arg->refs->write_options.block_size / 2);
|
||||
logs[logs_nr].value.update.new_hash = old_ref.value.val1;
|
||||
memcpy(logs[logs_nr].value.update.new_hash, old_ref.value.val1, GIT_MAX_RAWSZ);
|
||||
logs_nr++;
|
||||
|
||||
/*
|
||||
@@ -1515,10 +1498,6 @@ done:
|
||||
for (i = 0; i < logs_nr; i++) {
|
||||
if (!strcmp(logs[i].refname, "HEAD"))
|
||||
continue;
|
||||
if (logs[i].value.update.old_hash == old_ref.value.val1)
|
||||
logs[i].value.update.old_hash = NULL;
|
||||
if (logs[i].value.update.new_hash == old_ref.value.val1)
|
||||
logs[i].value.update.new_hash = NULL;
|
||||
logs[i].refname = NULL;
|
||||
reftable_log_record_release(&logs[i]);
|
||||
}
|
||||
@@ -2180,7 +2159,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
|
||||
dest->value_type = REFTABLE_LOG_DELETION;
|
||||
} else {
|
||||
if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
|
||||
dest->value.update.old_hash = last_hash;
|
||||
memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);
|
||||
last_hash = logs[i].value.update.new_hash;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user