|
2 | 2 | #include "il2cppGC.h" |
3 | 3 | #include "il2cppBridge.h" |
4 | 4 | #include <math.h> |
5 | | -#include <vector> |
6 | 5 | #include <algorithm> |
7 | 6 |
|
8 | 7 | #if defined(_WIN32) |
@@ -59,55 +58,36 @@ void* il2cpp_New(uint32_t sz, uint32_t typeID, uint8_t isNoRef, IL2CPP_FINALIZER |
59 | 58 | return obj; |
60 | 59 | } |
61 | 60 |
|
62 | | -struct GCRootItem |
| 61 | +void il2cpp_CommitRoots(il2cppRootItem* roots, uint32_t num) |
63 | 62 | { |
64 | | - uint8_t* Start; |
65 | | - uint32_t Length; |
66 | | - |
67 | | - GCRootItem(uint8_t* start, uint32_t len) |
68 | | - : Start(start) |
69 | | - , Length(len) |
| 63 | + std::sort(roots, roots + num, |
| 64 | + [](const il2cppRootItem& lhs, const il2cppRootItem& rhs) |
70 | 65 | { |
71 | | - } |
72 | | -}; |
73 | | - |
74 | | -static std::vector<GCRootItem> g_Roots; |
75 | | -void il2cpp_AddRoot(void* ptr, uint32_t len) |
76 | | -{ |
77 | | - g_Roots.emplace_back(static_cast<uint8_t*>(ptr), len); |
78 | | -} |
79 | | - |
80 | | -void il2cpp_CommitRoots() |
81 | | -{ |
82 | | - std::sort(g_Roots.begin(), g_Roots.end(), |
83 | | - [](const GCRootItem& lhs, const GCRootItem& rhs) |
84 | | - { |
85 | | - return lhs.Start < rhs.Start; |
| 66 | + return lhs.Ptr < rhs.Ptr; |
86 | 67 | }); |
87 | 68 |
|
88 | 69 | uint8_t* start = nullptr; |
89 | 70 | uint8_t* end = nullptr; |
90 | | - for (const auto& item : g_Roots) |
| 71 | + for (const il2cppRootItem* itEnd = roots + num; |
| 72 | + roots < itEnd; |
| 73 | + ++roots) |
91 | 74 | { |
| 75 | + const il2cppRootItem& item = *roots; |
92 | 76 | if (start) |
93 | 77 | { |
94 | | - if (item.Start <= end) |
| 78 | + if (item.Ptr <= end) |
95 | 79 | { |
96 | 80 | end += item.Length; |
97 | 81 | continue; |
98 | 82 | } |
99 | 83 | il2cpp_GC_AddRoots(start, end); |
100 | 84 | } |
101 | 85 |
|
102 | | - start = item.Start; |
103 | | - end = item.Start + item.Length; |
| 86 | + start = item.Ptr; |
| 87 | + end = item.Ptr + item.Length; |
104 | 88 | } |
105 | 89 | if (start) |
106 | 90 | il2cpp_GC_AddRoots(start, end); |
107 | | - |
108 | | - g_Roots.clear(); |
109 | | - g_Roots.reserve(0); |
110 | | - auto tmp = std::move(g_Roots); |
111 | 91 | } |
112 | 92 |
|
113 | 93 | void il2cpp_Yield() |
|
0 commit comments