MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getViewFactory

Method getViewFactory

valdi/src/valdi/runtime/Views/GlobalViewFactories.cpp:41–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 std::lock_guard<Mutex> guard(_mutex);
40 _viewClassReplacements[className] = replacementClassName;
41
42 // Remove the associated view factory for the class we want to replace, so that next queries to
43 // getViewFactory will resolve our replacement view factory.
44 const auto& it = _viewFactories.find(className);
45 if (it != _viewFactories.end()) {
46 _viewFactories.erase(it);
47 }
48}
49
50Ref<ViewFactory> GlobalViewFactories::getViewFactory(const StringBox& className) {
51 std::unique_lock<Mutex> guard(_mutex);
52
53 const auto& it = _viewFactories.find(className);
54 if (it != _viewFactories.end()) {
55 return it->second;
56 }
57
58 const auto& replacementIt = _viewClassReplacements.find(className);
59 if (replacementIt != _viewClassReplacements.end()) {
60 auto replacementClassName = replacementIt->second;
61 // Reuse the replacement class' existing factory so both names share a single view pool.
62 // Copy the Ref before inserting: FlatMap insertion can invalidate the found iterator.
63 auto existingIt = _viewFactories.find(replacementClassName);
64 if (existingIt != _viewFactories.end()) {
65 auto existingFactory = existingIt->second;
66 _viewFactories[className] = existingFactory;
67 return existingFactory;
68 }
69 // Release the mutex during creation, like the non-replacement path below. Factory
70 // creation class-loads the view class and binds attributes through JNI; holding _mutex
71 // across it blocks clearViewPools() on the main thread during applicationWillPause.
72 guard.unlock();
73 auto viewFactory = createViewFactory(replacementClassName);
74 guard.lock();
75 // Another thread may have created a factory under either name while the mutex was
76 // released; link to it instead of overwriting, so the view pool doesn't get split.
77 auto createdIt = _viewFactories.find(className);

Callers 1

Calls 5

createViewFactoryFunction · 0.85
endMethod · 0.65
findMethod · 0.45
unlockMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected