This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Optimization for strcpy(..., "") in file 'install.c'
Type: enhancement Stage: patch review
Components: Windows Versions: Python 3.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, dogbert2, martin.panter, paul.moore, steve.dower, tim.golden, zach.ware
Priority: low Keywords: patch

Created on 2015-05-20 21:23 by dogbert2, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
install.c.patch dogbert2, 2015-05-20 21:23 Patch File for Above bug report,,,
Messages (4)
msg243697 - (view) Author: Bill Parker (dogbert2) * Date: 2015-05-20 21:23
In reviewing calls to strcpy(<string>, ""), I found three instances which could be re-written as *<string> = '\0'; which would save the minor overhead of a function call.  The patch file is below:

--- install.c.orig      2015-05-20 14:11:27.723397005 -0700
+++ install.c   2015-05-20 14:14:00.862860244 -0700
@@ -1640,8 +1640,8 @@
                                             PSWIZB_BACK);
                     SetDlgItemText(hwnd, IDC_PATH, "");
                     SetDlgItemText(hwnd, IDC_INSTALL_PATH, "");
-                    strcpy(python_dir, "");
-                    strcpy(pythondll, "");
+                   *python_dir = '\0'; /*  replaces strcpy(python_dir, "") */
+                   *pythondll = '\0';  /*  replaces strcpy(pythondll, "")  */
                 } else {
                     char *pbuf;
                     int result;
@@ -1680,7 +1680,7 @@
                         }
                         free(pbuf);
                     } else
-                        strcpy(pythondll, "");
+                       *pythondll = '\0';  /*  replaces strcpy(pythondll, "")  */
                     /* retrieve the scheme for this version */
                     {
                         char install_path[_MAX_PATH];

I am attaching the patch file to this bug report...
msg243740 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2015-05-21 08:41
The patch looks fine to me, although I don't think you need the comment showing the old code. The new code is perfectly clear on its own.
msg243745 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-05-21 11:19
For the record, the file being patched is PC/bdist_wininst/install.c

My opinion is the original is more readable, and unless this is some inner loop bottleneck here it seems like premature optimization.
msg243792 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2015-05-21 21:03
I agree with vadmium and also note that many compilers (though I don't know about MSVC) can optimize the strcpy call away.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68438
2015-05-21 21:03:50benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg243792

resolution: works for me
2015-05-21 12:14:43serhiy.storchakasetpriority: normal -> low
stage: patch review
versions: + Python 3.5, - Python 3.4
2015-05-21 11:19:38martin.pantersetnosy: + martin.panter
messages: + msg243745
2015-05-21 08:41:51paul.mooresetnosy: + paul.moore
messages: + msg243740
2015-05-20 21:23:09dogbert2create