Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Henrie <alexhenrie24@gmail.com>2019-10-01 05:29:36 +0300
committerJunio C Hamano <gitster@pobox.com>2019-10-02 09:04:23 +0300
commit54a80a9ad84af001470ea22fb0a14f6dc844b9c9 (patch)
treedd1bab35137598fbf4c3bc140137497b05a02397 /wrapper.c
parentbaed6bbb5b56a501d1137e53caba614f77c3435d (diff)
wrapper: use a loop instead of repetitive statements
A check into the history of this code revealed no particular reason for the code to be written in this way. All popular compilers are capable of unrolling loops if it benefits performance, and once this code is replaced with a loop, the magic number 6 used in multiple places in this function can be replaced with a named constant. Reviewed-by: Derrick Stolee <stolee@gmail.com> Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/wrapper.c b/wrapper.c
index 1e45ab7b92..54541386c1 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -506,13 +506,12 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
filename_template = &pattern[len - 6 - suffix_len];
for (count = 0; count < TMP_MAX; ++count) {
uint64_t v = value;
+ int i;
/* Fill in the random bits. */
- filename_template[0] = letters[v % num_letters]; v /= num_letters;
- filename_template[1] = letters[v % num_letters]; v /= num_letters;
- filename_template[2] = letters[v % num_letters]; v /= num_letters;
- filename_template[3] = letters[v % num_letters]; v /= num_letters;
- filename_template[4] = letters[v % num_letters]; v /= num_letters;
- filename_template[5] = letters[v % num_letters]; v /= num_letters;
+ for (i = 0; i < 6; i++) {
+ filename_template[i] = letters[v % num_letters];
+ v /= num_letters;
+ }
fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
if (fd >= 0)