[Issue 24700] MsCoffObj_getsegment is really slow O(n^2)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 13 12:27:13 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #1 from Dennis <dkorpel at live.nl> ---
N.b. even a dumb patch like this would mostly fix it, since it's trying to get
the same section over and over:
```
--- a/compiler/src/dmd/backend/mscoffobj.d
+++ b/compiler/src/dmd/backend/mscoffobj.d
@@ -1357,16 +1357,29 @@ int MsCoffObj_jmpTableSegment(Symbol *s)
 @trusted
 segidx_t MsCoffObj_getsegment(const(char)* sectname, uint flags)
 {
+    __gshared segidx_t lastFind = 1;
     //printf("getsegment(%s)\n", sectname);
     assert(strlen(sectname) <= 8);      // so it won't go into string_table
     if (!(flags & IMAGE_SCN_LNK_COMDAT))
     {
+        if (lastFind < SegData.length)
+        {
+            seg_data *pseg = SegData[lastFind];
+            if (!(ScnhdrTab[pseg.SDshtidx].Characteristics &
IMAGE_SCN_LNK_COMDAT) &&
+                strncmp(cast(const(char)* )ScnhdrTab[pseg.SDshtidx].Name,
sectname, 8) == 0)
+            {
+                //printf("\t%s\n", sectname);
+                return lastFind;         // return existing segment
+            }
+        }
+
         for (segidx_t seg = 1; seg < SegData.length; seg++)
         {   seg_data *pseg = SegData[seg];
             if (!(ScnhdrTab[pseg.SDshtidx].Characteristics &
IMAGE_SCN_LNK_COMDAT) &&
                 strncmp(cast(const(char)* )ScnhdrTab[pseg.SDshtidx].Name,
sectname, 8) == 0)
             {
                 //printf("\t%s\n", sectname);
+                lastFind = seg;
                 return seg;         // return existing segment
             }
         }
```

--


More information about the Digitalmars-d-bugs mailing list