ref_transaction_commit(): remove local variables n and updates
These microoptimizations don't make a significant difference in speed. And they cause problems if somebody ever wants to modify the function to add updates to a transaction as part of processing it, as will happen shortly. Make the same changes in initial_ref_transaction_commit(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Michael Haggerty committed
Apr 22, 2016 at 00:02 UTC
efe472813d60befd72d6e2797934c90b22a26c93
1 file changed
+20
-22
refs/files-backend.c
+20
-22
@@ -3076,8 +3076,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3076
struct strbuf *err)
3077
{
3078
int ret = 0, i;
3079
- int n = transaction->nr;
3080
- struct ref_update **updates = transaction->updates;
3079
struct string_list refs_to_delete = STRING_LIST_INIT_NODUP;
3080
struct string_list_item *ref_to_delete;
3081
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
@@ -3087,14 +3085,15 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3085
if (transaction->state != REF_TRANSACTION_OPEN)
3086
die("BUG: commit called for transaction that is not open");
3087
3090
- if (!n) {
3088
+ if (!transaction->nr) {
3089
transaction->state = REF_TRANSACTION_CLOSED;
3090
return 0;
3091
}
3092
3093
/* Fail if a refname appears more than once in the transaction: */
3096
- for (i = 0; i < n; i++)
3097
- string_list_append(&affected_refnames, updates[i]->refname);
3094
+ for (i = 0; i < transaction->nr; i++)
3095
+ string_list_append(&affected_refnames,
3096
+ transaction->updates[i]->refname);
3097
string_list_sort(&affected_refnames);
3098
if (ref_update_reject_duplicates(&affected_refnames, err)) {
3099
ret = TRANSACTION_GENERIC_ERROR;
@@ -3107,8 +3106,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3106
* lockfiles, ready to be activated. Only keep one lockfile
3107
* open at a time to avoid running out of file descriptors.
3108
*/
3110
- for (i = 0; i < n; i++) {
3111
- struct ref_update *update = updates[i];
3109
+ for (i = 0; i < transaction->nr; i++) {
3110
+ struct ref_update *update = transaction->updates[i];
3111
3112
if ((update->flags & REF_HAVE_NEW) &&
3113
is_null_sha1(update->new_sha1))
@@ -3178,8 +3177,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3177
}
3178
3179
/* Perform updates first so live commits remain referenced */
3181
- for (i = 0; i < n; i++) {
3182
- struct ref_update *update = updates[i];
3180
+ for (i = 0; i < transaction->nr; i++) {
3181
+ struct ref_update *update = transaction->updates[i];
3182
3183
if (update->flags & REF_NEEDS_COMMIT) {
3184
if (commit_ref_update(update->lock,
@@ -3197,8 +3196,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3196
}
3197
3198
/* Perform deletes now that updates are safely completed */
3200
- for (i = 0; i < n; i++) {
3201
- struct ref_update *update = updates[i];
3199
+ for (i = 0; i < transaction->nr; i++) {
3200
+ struct ref_update *update = transaction->updates[i];
3201
3202
if (update->flags & REF_DELETING) {
3203
if (delete_ref_loose(update->lock, update->type, err)) {
@@ -3223,9 +3222,9 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3222
cleanup:
3223
transaction->state = REF_TRANSACTION_CLOSED;
3224
3226
- for (i = 0; i < n; i++)
3227
- if (updates[i]->lock)
3228
- unlock_ref(updates[i]->lock);
3225
+ for (i = 0; i < transaction->nr; i++)
3226
+ if (transaction->updates[i]->lock)
3227
+ unlock_ref(transaction->updates[i]->lock);
3228
string_list_clear(&refs_to_delete, 0);
3229
string_list_clear(&affected_refnames, 0);
3230
return ret;
@@ -3243,8 +3242,6 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
3242
struct strbuf *err)
3243
{
3244
int ret = 0, i;
3246
- int n = transaction->nr;
3247
- struct ref_update **updates = transaction->updates;
3245
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
3246
3247
assert(err);
@@ -3253,8 +3250,9 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
3250
die("BUG: commit called for transaction that is not open");
3251
3252
/* Fail if a refname appears more than once in the transaction: */
3256
- for (i = 0; i < n; i++)
3257
- string_list_append(&affected_refnames, updates[i]->refname);
3253
+ for (i = 0; i < transaction->nr; i++)
3254
+ string_list_append(&affected_refnames,
3255
+ transaction->updates[i]->refname);
3256
string_list_sort(&affected_refnames);
3257
if (ref_update_reject_duplicates(&affected_refnames, err)) {
3258
ret = TRANSACTION_GENERIC_ERROR;
@@ -3276,8 +3274,8 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
3274
if (for_each_rawref(ref_present, &affected_refnames))
3275
die("BUG: initial ref transaction called with existing refs");
3276
3279
- for (i = 0; i < n; i++) {
3280
- struct ref_update *update = updates[i];
3277
+ for (i = 0; i < transaction->nr; i++) {
3278
+ struct ref_update *update = transaction->updates[i];
3279
3280
if ((update->flags & REF_HAVE_OLD) &&
3281
!is_null_sha1(update->old_sha1))
@@ -3297,8 +3295,8 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
3295
goto cleanup;
3296
}
3297
3300
- for (i = 0; i < n; i++) {
3301
- struct ref_update *update = updates[i];
3298
+ for (i = 0; i < transaction->nr; i++) {
3299
+ struct ref_update *update = transaction->updates[i];
3300
3301
if ((update->flags & REF_HAVE_NEW) &&
3302
!is_null_sha1(update->new_sha1))