11#include " ClassBuilder.h"
2- #if TARGET_CPU_X86_64 || TARGET_CPU_X86
3- #include " SpinLock.h"
4- #endif
52
63namespace tns {
74
85// Moved this method in a separate .cpp file because ARC destroys the class
96// created with objc_allocateClassPair when the control leaves this method scope
10- // TODO: revist this as there are x86 simulator issues, so maybe a lock is
11- // needed regardless
7+ // TODO: revist this. Maybe a lock is needed regardless
128Class ClassBuilder::GetExtendedClass (std::string baseClassName,
13- std::string staticClassName) {
14- #if TARGET_CPU_X86_64 || TARGET_CPU_X86
15- // X86 simulators have this bugged, so we fallback to old behavior
16- static SpinMutex m;
17- SpinLock lock (m);
9+ std::string staticClassName,
10+ std::string suffix) {
1811 Class baseClass = objc_getClass (baseClassName.c_str ());
1912 std::string name =
2013 !staticClassName.empty ()
2114 ? staticClassName
22- : baseClassName + " _" +
23- std::to_string (++ClassBuilder::classNameCounter_);
24- Class clazz = objc_getClass (name.c_str ());
25-
26- if (clazz != nil) {
27- int i = 1 ;
28- std::string initialName = name;
29- while (clazz != nil) {
30- name = initialName + std::to_string (i++);
31- clazz = objc_getClass (name.c_str ());
32- }
33- }
34-
35- clazz = objc_allocateClassPair (baseClass, name.c_str (), 0 );
36-
37- objc_registerClassPair (clazz);
38- return clazz;
39- #else
40- Class baseClass = objc_getClass (baseClassName.c_str ());
41- std::string name =
42- !staticClassName.empty ()
43- ? staticClassName
44- : baseClassName + " _" +
15+ : baseClassName + suffix + " _" +
4516 std::to_string (++ClassBuilder::classNameCounter_);
4617 // here we could either call objc_getClass with the name to see if the class
4718 // already exists or we can just try allocating it, which will return nil if
@@ -60,7 +31,6 @@ Class ClassBuilder::GetExtendedClass(std::string baseClassName,
6031
6132 objc_registerClassPair (clazz);
6233 return clazz;
63- #endif
6434}
6535
6636} // namespace tns
0 commit comments