@@ -518,7 +518,7 @@ unittest
518518 // Sort top-level zones by duration. If there is one top-level zone per frame, this
519519 // sorts frames by duration: useful to get the worst-case frames.
520520
521- // This example also uses C malloc/free, std.typecons.scoped and std.container.Array
521+ // This example also uses C malloc/free and std.typecons.scoped
522522 // to show how to do this without using the GC.
523523
524524 import tharsis.prof;
@@ -556,6 +556,24 @@ unittest
556556 // nestLevel of 1 is toplevel.
557557 auto topLevel = zones.filter! (z => z.nestLevel == 1 );
558558
559+ const size_t topLevelLength = zones.walkLength;
560+ // TODO replace with std.allocator, or better, new containers once added to Phobos
561+ ZoneData[] topLevelArray = (cast (ZoneData* )malloc(topLevelLength * ZoneData.sizeof))[0 .. topLevelLength];
562+ scope (exit) { free(topLevelArray.ptr); }
563+
564+ topLevel.copy(topLevelArray);
565+ topLevelArray.sort! ((a, b) => a.duration > b.duration);
566+ import std.stdio ;
567+ // Print the 4 longest frames.
568+ foreach (frame; topLevelArray[0 .. 4 ])
569+ {
570+ writeln(frame);
571+ }
572+
573+ auto worst = topLevelArray[0 ];
574+
575+ /* Code based on std.container.array.Array: broken due to DMD 2.068 changes.
576+ * Getting obsolete anyway, as containers are finally being redesigned by Andrei Alexandrescu.
559577 import std.container;
560578 // std.container.Array constructor builds an RAII array containing zones from topLevel.
561579 // We need an array as we need random access to sort the zones (ZoneRange generates
@@ -571,6 +589,7 @@ unittest
571589 }
572590
573591 auto worst = topLevelArray[0];
592+ */
574593
575594 // Print details about all zones in the worst frame.
576595 writeln(" Zones in the worst frame:" );
0 commit comments