OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.5 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../make/make-3.82-0004-improve-glob-speed.patch
  5. # Copyright (C) 2012 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From b905f2002daaacc62cc5c083ebc6f7ba787a793e Mon Sep 17 00:00:00 2001
  17. From: Christian Wiese <chris@opensde.org>
  18. Date: Mon, 22 Oct 2012 17:58:00 +0200
  19. Subject: [PATCH] improve glob speed
  20. ChangeLog:
  21. 2011-05-07 Paul Smith <psmith@gnu.org>
  22. * read.c (parse_file_seq): Ensure existence checks use glob().
  23. 2011-05-01 Paul Smith <psmith@gnu.org>
  24. * read.c (parse_file_seq): Don't try to invoke glob() unless there
  25. are potential wildcard characters in the filename. Performance
  26. enhancement suggested by Michael Meeks <michael.meeks@novell.com>
  27. tests/Changelog:
  28. 2011-05-07 Paul Smith <psmith@gnu.org>
  29. * scripts/functions/wildcard: Verify wildcard used to test for
  30. file existence/non-existence.
  31. ---
  32. read.c | 58 ++++++++++++++++++++++---------------
  33. tests/scripts/functions/wildcard | 12 ++++++++
  34. 2 files changed, 46 insertions(+), 24 deletions(-)
  35. diff --git a/read.c b/read.c
  36. index 9dfd4ea..8587e85 100644
  37. --- a/read.c
  38. +++ b/read.c
  39. @@ -2904,6 +2904,7 @@ parse_file_seq (char **stringp, unsigned int size, int stopchar,
  40. const char *name;
  41. const char **nlist = 0;
  42. char *tildep = 0;
  43. + int globme = 1;
  44. #ifndef NO_ARCHIVES
  45. char *arname = 0;
  46. char *memname = 0;
  47. @@ -3112,32 +3113,40 @@ parse_file_seq (char **stringp, unsigned int size, int stopchar,
  48. }
  49. #endif /* !NO_ARCHIVES */
  50. - switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
  51. - {
  52. - case GLOB_NOSPACE:
  53. - fatal (NILF, _("virtual memory exhausted"));
  54. + /* glob() is expensive: don't call it unless we need to. */
  55. + if (!(flags & PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
  56. + {
  57. + globme = 0;
  58. + i = 1;
  59. + nlist = &name;
  60. + }
  61. + else
  62. + switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
  63. + {
  64. + case GLOB_NOSPACE:
  65. + fatal (NILF, _("virtual memory exhausted"));
  66. - case 0:
  67. - /* Success. */
  68. - i = gl.gl_pathc;
  69. - nlist = (const char **)gl.gl_pathv;
  70. - break;
  71. + case 0:
  72. + /* Success. */
  73. + i = gl.gl_pathc;
  74. + nlist = (const char **)gl.gl_pathv;
  75. + break;
  76. - case GLOB_NOMATCH:
  77. - /* If we want only existing items, skip this one. */
  78. - if (flags & PARSEFS_EXISTS)
  79. - {
  80. - i = 0;
  81. - break;
  82. - }
  83. - /* FALLTHROUGH */
  84. + case GLOB_NOMATCH:
  85. + /* If we want only existing items, skip this one. */
  86. + if (flags & PARSEFS_EXISTS)
  87. + {
  88. + i = 0;
  89. + break;
  90. + }
  91. + /* FALLTHROUGH */
  92. - default:
  93. - /* By default keep this name. */
  94. - i = 1;
  95. - nlist = &name;
  96. - break;
  97. - }
  98. + default:
  99. + /* By default keep this name. */
  100. + i = 1;
  101. + nlist = &name;
  102. + break;
  103. + }
  104. /* For each matched element, add it to the list. */
  105. while (i-- > 0)
  106. @@ -3177,7 +3186,8 @@ parse_file_seq (char **stringp, unsigned int size, int stopchar,
  107. #endif /* !NO_ARCHIVES */
  108. NEWELT (concat (2, prefix, nlist[i]));
  109. - globfree (&gl);
  110. + if (globme)
  111. + globfree (&gl);
  112. #ifndef NO_ARCHIVES
  113. if (arname)
  114. diff --git a/tests/scripts/functions/wildcard b/tests/scripts/functions/wildcard
  115. index 2841f5d..bcd84ad 100644
  116. --- a/tests/scripts/functions/wildcard
  117. +++ b/tests/scripts/functions/wildcard
  118. @@ -88,4 +88,16 @@ all: ; @echo $(wildcard xz--y*.7)
  119. !,
  120. '', "\n");
  121. +# TEST #5: wildcard used to verify file existence
  122. +
  123. +touch('xxx.yyy');
  124. +
  125. +run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
  126. + '', "file=xxx.yyy\n");
  127. +
  128. +unlink('xxx.yyy');
  129. +
  130. +run_make_test(q!exists: ; @echo file=$(wildcard xxx.yyy)!,
  131. + '', "file=\n");
  132. +
  133. 1;
  134. --
  135. 1.7.2.3