{"thread":{"id":"51939","subject":"[PATCH v3] wrapper: use a loop instead of repetitive statements","startedAt":"2019-09-29T00:57:07Z","lastAt":"2019-09-29T00:57:07Z","messageCount":1,"participants":["Alex Henrie"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"383094","messageId":"20190929005701.734095-1-alexhenrie24@gmail.com","threadId":"51939","inReplyTo":null,"subject":"[PATCH v3] wrapper: use a loop instead of repetitive statements","fromName":"Alex Henrie","fromEmail":"alexhenrie24@gmail.com","sentAt":"2019-09-29T00:57:01Z","receivedAt":"2019-09-29T00:57:07Z","isPatch":true,"sender":{"key":"alexhenrie24@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5951993?v=4"},"body":"A check into the history of this code revealed no particular reason for\nthe code to be written in this way. All popular compilers are capable of\nunrolling loops if it benefits performance, and once this code is\nreplaced with a loop, the magic number 6 used in multiple places in this\nfunction can be replaced with a named constant.\n\nReviewed-by: Derrick Stolee <stolee@gmail.com>\nReviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nReviewed-by: Jeff King <peff@peff.net>\nSigned-off-by: Alex Henrie <alexhenrie24@gmail.com>\n---\n wrapper.c | 11 +++++------\n 1 file changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/wrapper.c b/wrapper.c\nindex c55d7722d7..c23ac6adcd 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -469,13 +469,12 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)\n \tfilename_template = &pattern[len - 6 - suffix_len];\n \tfor (count = 0; count < TMP_MAX; ++count) {\n \t\tuint64_t v = value;\n+\t\tint i;\n \t\t/* Fill in the random bits. */\n-\t\tfilename_template[0] = letters[v % num_letters]; v /= num_letters;\n-\t\tfilename_template[1] = letters[v % num_letters]; v /= num_letters;\n-\t\tfilename_template[2] = letters[v % num_letters]; v /= num_letters;\n-\t\tfilename_template[3] = letters[v % num_letters]; v /= num_letters;\n-\t\tfilename_template[4] = letters[v % num_letters]; v /= num_letters;\n-\t\tfilename_template[5] = letters[v % num_letters]; v /= num_letters;\n+\t\tfor (i = 0; i < 6; i++) {\n+\t\t\tfilename_template[i] = letters[v % num_letters];\n+\t\t\tv /= num_letters;\n+\t\t}\n \n \t\tfd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);\n \t\tif (fd >= 0)\n-- \n2.23.0\n\n"}]}