make-3.82-glob-speedup.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. change from upstream to speed up by skipping unused globs
  2. https://bugs.gentoo.org/382845
  3. http://cvs.savannah.gnu.org/viewvc/make/read.c?root=make&r1=1.198&r2=1.200
  4. Revision 1.200
  5. Sat May 7 14:36:12 2011 UTC (4 months, 1 week ago) by psmith
  6. Branch: MAIN
  7. Changes since 1.199: +1 -1 lines
  8. Inverted the boolean test from what I wanted it to be. Added a
  9. regression test to make sure this continues to work.
  10. Revision 1.199
  11. Mon May 2 00:18:06 2011 UTC (4 months, 2 weeks ago) by psmith
  12. Branch: MAIN
  13. Changes since 1.198: +35 -25 lines
  14. Avoid invoking glob() unless the filename has potential globbing
  15. characters in it, for performance improvements.
  16. --- a/read.c 2011/04/29 15:27:39 1.198
  17. +++ b/read.c 2011/05/07 14:36:12 1.200
  18. @@ -2901,6 +2901,7 @@
  19. const char *name;
  20. const char **nlist = 0;
  21. char *tildep = 0;
  22. + int globme = 1;
  23. #ifndef NO_ARCHIVES
  24. char *arname = 0;
  25. char *memname = 0;
  26. @@ -3109,32 +3110,40 @@
  27. }
  28. #endif /* !NO_ARCHIVES */
  29. - switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
  30. - {
  31. - case GLOB_NOSPACE:
  32. - fatal (NILF, _("virtual memory exhausted"));
  33. -
  34. - case 0:
  35. - /* Success. */
  36. - i = gl.gl_pathc;
  37. - nlist = (const char **)gl.gl_pathv;
  38. - break;
  39. -
  40. - case GLOB_NOMATCH:
  41. - /* If we want only existing items, skip this one. */
  42. - if (flags & PARSEFS_EXISTS)
  43. - {
  44. - i = 0;
  45. - break;
  46. - }
  47. - /* FALLTHROUGH */
  48. -
  49. - default:
  50. - /* By default keep this name. */
  51. + /* glob() is expensive: don't call it unless we need to. */
  52. + if (!(flags & PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
  53. + {
  54. + globme = 0;
  55. i = 1;
  56. nlist = &name;
  57. - break;
  58. - }
  59. + }
  60. + else
  61. + switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
  62. + {
  63. + case GLOB_NOSPACE:
  64. + fatal (NILF, _("virtual memory exhausted"));
  65. +
  66. + case 0:
  67. + /* Success. */
  68. + i = gl.gl_pathc;
  69. + nlist = (const char **)gl.gl_pathv;
  70. + break;
  71. +
  72. + case GLOB_NOMATCH:
  73. + /* If we want only existing items, skip this one. */
  74. + if (flags & PARSEFS_EXISTS)
  75. + {
  76. + i = 0;
  77. + break;
  78. + }
  79. + /* FALLTHROUGH */
  80. +
  81. + default:
  82. + /* By default keep this name. */
  83. + i = 1;
  84. + nlist = &name;
  85. + break;
  86. + }
  87. /* For each matched element, add it to the list. */
  88. while (i-- > 0)
  89. @@ -3174,7 +3183,8 @@
  90. #endif /* !NO_ARCHIVES */
  91. NEWELT (concat (2, prefix, nlist[i]));
  92. - globfree (&gl);
  93. + if (globme)
  94. + globfree (&gl);
  95. #ifndef NO_ARCHIVES
  96. if (arname)