File tree 2 files changed +19
-1
lines changed 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,9 @@ set(WITH_WHEREAMI yes
89
89
set (WITH_ZLIB yes
90
90
CACHE BOOL "Compile with ZLIB Library" )
91
91
92
+ set (WITH_LCOMPILERS_FAST_ALLOC yes
93
+ CACHE BOOL "Compile with fast allocator" )
94
+
92
95
# Build to wasm
93
96
set (LPYTHON_BUILD_TO_WASM no
94
97
CACHE BOOL "Compile LPython To WASM" )
@@ -97,6 +100,7 @@ if (LPYTHON_BUILD_TO_WASM)
97
100
set (HAVE_BUILD_TO_WASM yes )
98
101
SET (WITH_WHEREAMI no )
99
102
SET (WITH_ZLIB no )
103
+ SET (WITH_LCOMPILERS_FAST_ALLOC no )
100
104
add_definitions ("-DHAVE_BUILD_TO_WASM=1" )
101
105
endif ()
102
106
@@ -112,6 +116,10 @@ if (WITH_ZLIB)
112
116
find_package (StaticZLIB REQUIRED)
113
117
endif ()
114
118
119
+ if (WITH_LCOMPILERS_FAST_ALLOC)
120
+ add_definitions ("-DLCOMPILERS_FAST_ALLOC=1" )
121
+ endif ()
122
+
115
123
# LLVM
116
124
set (WITH_LLVM no CACHE BOOL "Build with LLVM support" )
117
125
set (WITH_TARGET_AARCH64 no CACHE BOOL "Enable target AARCH64" )
Original file line number Diff line number Diff line change @@ -52,15 +52,25 @@ class Allocator
52
52
// force new_chunk() not to get inlined, but there is no standard way of
53
53
// doing it. This try/catch approach effectively achieves the same using
54
54
// standard C++.
55
+ #ifdef LCOMPILERS_FAST_ALLOC
55
56
try {
57
+ #endif
56
58
LCOMPILERS_ASSERT (start != nullptr );
57
59
size_t addr = current_pos;
58
60
current_pos += align (s);
59
- if (size_current () > size_total ()) throw std::bad_alloc ();
61
+ if (size_current () > size_total ()) {
62
+ #ifdef LCOMPILERS_FAST_ALLOC
63
+ throw std::bad_alloc ();
64
+ #else
65
+ return new_chunk (s);
66
+ #endif
67
+ }
60
68
return (void *)addr;
69
+ #ifdef LCOMPILERS_FAST_ALLOC
61
70
} catch (const std::bad_alloc &e) {
62
71
return new_chunk (s);
63
72
}
73
+ #endif
64
74
}
65
75
66
76
void *new_chunk (size_t s) {
You can’t perform that action at this time.
0 commit comments