{"thread":{"id":"10969","subject":"[PATCH] Avoid recalculating filename string pointer.","startedAt":"2007-11-22T00:59:41Z","lastAt":"2007-11-25T21:43:58Z","messageCount":4,"participants":["André Goddard Rosa","Mike Hommey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60588","messageId":"b8bf37780711211659i65a99493te3e3d5cee008ae7d@mail.gmail.com","threadId":"10969","inReplyTo":null,"subject":"[PATCH] Avoid recalculating filename string pointer.","fromName":"André Goddard Rosa","fromEmail":"andre.goddard@gmail.com","sentAt":"2007-11-22T00:59:41Z","receivedAt":"2007-11-22T00:59:41Z","isPatch":true,"sender":{"key":"andre.goddard@gmail.com","avatar":null},"body":"Hi, all!\n\n    Please cc: me as I'm not subscribed. I'm sending the patch inline\nonly for review, probably it is mangled.\n    Please use the attached patch if you agree with it. Sorry about\nsending it attached.\n\n>From b6b05d9f8d8e053df4e971cd229e03b778c4d163 Mon Sep 17 00:00:00 2001\nFrom: Andre Goddard Rosa <andre.goddard@gmail.com>\nDate: Tue, 27 Nov 2007 10:17:54 -0200\nSubject: [PATCH] Avoid recalculating filename string pointer.\n\nSigned-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>\n---\n fast-import.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 98c2bd5..2d262eb 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2304,11 +2304,13 @@ int main(int argc, const char **argv)\n \t\telse if (!prefixcmp(a, \"--export-marks=\"))\n \t\t\tmark_file = a + 15;\n \t\telse if (!prefixcmp(a, \"--export-pack-edges=\")) {\n+\t\t\tchar *filename = a + 20;\n+\n \t\t\tif (pack_edges)\n \t\t\t\tfclose(pack_edges);\n-\t\t\tpack_edges = fopen(a + 20, \"a\");\n+\t\t\tpack_edges = fopen(filename, \"a\");\n \t\t\tif (!pack_edges)\n-\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n+\t\t\t\tdie(\"Cannot open %s: %s\", filename, strerror(errno));\n \t\t} else if (!strcmp(a, \"--force\"))\n \t\t\tforce_update = 1;\n \t\telse if (!strcmp(a, \"--quiet\"))\n-- \n1.5.3.6.861.gd794-dirty\n\n\nFrom b6b05d9f8d8e053df4e971cd229e03b778c4d163 Mon Sep 17 00:00:00 2001\nFrom: Andre Goddard Rosa <andre.goddard@gmail.com>\nDate: Tue, 27 Nov 2007 10:17:54 -0200\nSubject: [PATCH] Avoid recalculating filename string pointer.\n\nSigned-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>\n---\n fast-import.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 98c2bd5..2d262eb 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2304,11 +2304,13 @@ int main(int argc, const char **argv)\n \t\telse if (!prefixcmp(a, \"--export-marks=\"))\n \t\t\tmark_file = a + 15;\n \t\telse if (!prefixcmp(a, \"--export-pack-edges=\")) {\n+\t\t\tchar *filename = a + 20;\n+\n \t\t\tif (pack_edges)\n \t\t\t\tfclose(pack_edges);\n-\t\t\tpack_edges = fopen(a + 20, \"a\");\n+\t\t\tpack_edges = fopen(filename, \"a\");\n \t\t\tif (!pack_edges)\n-\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n+\t\t\t\tdie(\"Cannot open %s: %s\", filename, strerror(errno));\n \t\t} else if (!strcmp(a, \"--force\"))\n \t\t\tforce_update = 1;\n \t\telse if (!strcmp(a, \"--quiet\"))\n-- \n1.5.3.6.861.gd794-dirty\n\n"},{"id":"60703","messageId":"20071122195457.GB19675@glandium.org","threadId":"10969","inReplyTo":"b8bf37780711211659i65a99493te3e3d5cee008ae7d@mail.gmail.com","subject":"Re: [PATCH] Avoid recalculating filename string pointer.","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-11-22T19:54:57Z","receivedAt":"2007-11-22T19:54:57Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"On Wed, Nov 21, 2007 at 10:59:41PM -0200, André Goddard Rosa wrote:\n> --- a/fast-import.c\n> +++ b/fast-import.c\n> @@ -2304,11 +2304,13 @@ int main(int argc, const char **argv)\n>  \t\telse if (!prefixcmp(a, \"--export-marks=\"))\n>  \t\t\tmark_file = a + 15;\n>  \t\telse if (!prefixcmp(a, \"--export-pack-edges=\")) {\n> +\t\t\tchar *filename = a + 20;\n> +\n>  \t\t\tif (pack_edges)\n>  \t\t\t\tfclose(pack_edges);\n> -\t\t\tpack_edges = fopen(a + 20, \"a\");\n> +\t\t\tpack_edges = fopen(filename, \"a\");\n>  \t\t\tif (!pack_edges)\n> -\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n> +\t\t\t\tdie(\"Cannot open %s: %s\", filename, strerror(errno));\n>  \t\t} else if (!strcmp(a, \"--force\"))\n>  \t\t\tforce_update = 1;\n>  \t\telse if (!strcmp(a, \"--quiet\"))\n\nNormally, the compiler takes care of such optimizations. It actually\ntakes care of it much better than you can do yourself, and doing it\nyourself can even sometimes generate less optimized code because it\ngets in the compiler optimizations'way.\n\nMike\n"},{"id":"60706","messageId":"7voddm3ubz.fsf@gitster.siamese.dyndns.org","threadId":"10969","inReplyTo":"20071122195457.GB19675@glandium.org","subject":"Re: [PATCH] Avoid recalculating filename string pointer.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-22T20:21:04Z","receivedAt":"2007-11-22T20:21:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Hommey <mh@glandium.org> writes:\n\n> On Wed, Nov 21, 2007 at 10:59:41PM -0200, André Goddard Rosa wrote:\n>> --- a/fast-import.c\n>> +++ b/fast-import.c\n>> @@ -2304,11 +2304,13 @@ int main(int argc, const char **argv)\n>>  \t\telse if (!prefixcmp(a, \"--export-marks=\"))\n>>  \t\t\tmark_file = a + 15;\n>>  \t\telse if (!prefixcmp(a, \"--export-pack-edges=\")) {\n>> +\t\t\tchar *filename = a + 20;\n>> +\n>>  \t\t\tif (pack_edges)\n>>  \t\t\t\tfclose(pack_edges);\n>> -\t\t\tpack_edges = fopen(a + 20, \"a\");\n>> +\t\t\tpack_edges = fopen(filename, \"a\");\n>>  \t\t\tif (!pack_edges)\n>> -\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n>> +\t\t\t\tdie(\"Cannot open %s: %s\", filename, strerror(errno));\n>>  \t\t} else if (!strcmp(a, \"--force\"))\n>>  \t\t\tforce_update = 1;\n>>  \t\telse if (!strcmp(a, \"--quiet\"))\n>\n> Normally, the compiler takes care of such optimizations. It actually\n> takes care of it much better than you can do yourself, and doing it\n> yourself can even sometimes generate less optimized code because it\n> gets in the compiler optimizations'way.\n\nTrue, but I think another point of the patch is to address the\nrisk of two instances of \"+ 20\" going out of sync if/when the\noption parsing is updated.\n\nNot that I think André meant the patch as defensive coding (the\nsubject suggests it was meant to be a micro-optimization), nor\nthis is the good way to address that risk factor (parse-options\nmay be a better match for it).\n"},{"id":"60874","messageId":"b8bf37780711251343s7f10804fmd2558d38dc434eb4@mail.gmail.com","threadId":"10969","inReplyTo":"b8bf37780711211659i65a99493te3e3d5cee008ae7d@mail.gmail.com","subject":"[Resend PATCH] Avoid recalculating filename string pointer.","fromName":"André Goddard Rosa","fromEmail":"andre.goddard@gmail.com","sentAt":"2007-11-25T21:43:58Z","receivedAt":"2007-11-25T21:43:58Z","isPatch":true,"sender":{"key":"andre.goddard@gmail.com","avatar":null},"body":"Hi, all!\n\n   Avoid calculating string position in 2 different places.\n\nFrom b6b05d9f8d8e053df4e971cd229e03b778c4d163 Mon Sep 17 00:00:00 2001\nFrom: Andre Goddard Rosa <andre.goddard@gmail.com>\nDate: Tue, 27 Nov 2007 10:17:54 -0200\nSubject: [PATCH] Avoid recalculating filename string pointer.\n\nSigned-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>\n---\n fast-import.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 98c2bd5..2d262eb 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2304,11 +2304,13 @@ int main(int argc, const char **argv)\n                else if (!prefixcmp(a, \"--export-marks=\"))\n                        mark_file = a + 15;\n                else if (!prefixcmp(a, \"--export-pack-edges=\")) {\n+                       char *filename = a + 20;\n+\n                        if (pack_edges)\n                                fclose(pack_edges);\n-                       pack_edges = fopen(a + 20, \"a\");\n+                       pack_edges = fopen(filename, \"a\");\n                        if (!pack_edges)\n-                               die(\"Cannot open %s: %s\", a + 20,\nstrerror(errno));\n+                               die(\"Cannot open %s: %s\", filename,\nstrerror(errno));\n                } else if (!strcmp(a, \"--force\"))\n                        force_update = 1;\n                else if (!strcmp(a, \"--quiet\"))\n--\n1.5.3.6.861.gd794-dirty\n\n\n\n-- \n[]s,\nAndré Goddard\n\n\nFrom b6b05d9f8d8e053df4e971cd229e03b778c4d163 Mon Sep 17 00:00:00 2001\nFrom: Andre Goddard Rosa <andre.goddard@gmail.com>\nDate: Tue, 27 Nov 2007 10:17:54 -0200\nSubject: [PATCH] Avoid recalculating filename string pointer.\n\nSigned-off-by: Andre Goddard Rosa <andre.goddard@gmail.com>\n---\n fast-import.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 98c2bd5..2d262eb 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2304,11 +2304,13 @@ int main(int argc, const char **argv)\n \t\telse if (!prefixcmp(a, \"--export-marks=\"))\n \t\t\tmark_file = a + 15;\n \t\telse if (!prefixcmp(a, \"--export-pack-edges=\")) {\n+\t\t\tchar *filename = a + 20;\n+\n \t\t\tif (pack_edges)\n \t\t\t\tfclose(pack_edges);\n-\t\t\tpack_edges = fopen(a + 20, \"a\");\n+\t\t\tpack_edges = fopen(filename, \"a\");\n \t\t\tif (!pack_edges)\n-\t\t\t\tdie(\"Cannot open %s: %s\", a + 20, strerror(errno));\n+\t\t\t\tdie(\"Cannot open %s: %s\", filename, strerror(errno));\n \t\t} else if (!strcmp(a, \"--force\"))\n \t\t\tforce_update = 1;\n \t\telse if (!strcmp(a, \"--quiet\"))\n-- \n1.5.3.6.861.gd794-dirty\n\n"}]}