RCLayout RCFetchOrComputeLayout()

in RenderCore/RCComputeRootLayout.mm [72:112]


RCLayout RCFetchOrComputeLayout(id<CKMountable> mountable,
                                const CKSizeRange &sizeRange,
                                CGSize parentSize,
                                RCLayout (*layoutFunction)(id<CKMountable> mountable, const CKSizeRange &sizeRange, CGSize parentSize))
{
  const RCLayoutCacheKey key {sizeRange, parentSize};

  if (currentLayoutWriteCache) {
    const auto it = currentLayoutWriteCache->map.find(mountable);
    if (it != currentLayoutWriteCache->map.end()) {
      const auto match = it->second.find(key);
      if (match != it->second.end()) {
        return match->second;
      }
    }
  }

  if (currentLayoutReadCache) {
    const auto it = currentLayoutReadCache->map.find(mountable);
    if (it != currentLayoutReadCache->map.end()) {
      const auto match = it->second.find(key);
      if (match != it->second.end()) {
        // Found a hit! Copy the cached layout for this node *and descendants*
        // from the read cache to the write cache, if there is one.
        if (currentLayoutWriteCache) {
          copyFromReadCacheToWriteCache(
            match->second,
            currentLayoutReadCache,
            currentLayoutWriteCache
          );
        }
        return match->second;
      }
    }
  }
  const RCLayout layout = layoutFunction(mountable, sizeRange, parentSize);
  if (currentLayoutWriteCache) {
    currentLayoutWriteCache->map[mountable].emplace(std::make_pair(key, layout));
  }
  return layout;
}