Repository: symfony/symfony
File: src/Symfony/Component/ErrorHandler/DebugClassLoader.php (PHP)

Code before:
    {
        $ownInterfaces = class_implements($class, false);

        if ($parent) {
            foreach (class_implements($parent, false) as $interface) {
                unset($ownInterfaces[$interface]);
            }
        }

        foreach ($ownInterfaces as $interface) {
            foreach (class_implements($interface) as $interface) {
                unset($ownInterfaces[$interface]);
            }
        }

        return $ownInterfaces;
    }

    /**
     * @param string $class The class being loaded and inspected for deprecation violations
     * @param string $use   The parent class, interface, or trait it extends, implements, or uses
     */
    private function areFromTheSameVendor(string $class, string $use): bool
    {
        if (!isset(self::$shortNamespacesCache[$class])) {
            $this->buildShortNamespaceEntry($class);
        }

        [$vendorLen, $vendor] = self::$shortNamespacesCache[$class];

        return 0 === strncmp($vendor, str_replace('_', '\\', $use), $vendorLen);
    }

    private function buildShortNamespaceEntry(string $class): void
    {
        // Anonymous classes carry a file path in their internal name instead of a namespace,
        // so the vendor prefix must be derived from the namespace declared in their source file.
        // Named classes use the class name itself as the lookup key.
        if (str_contains($class, "@anonymous\0")) {
            $refl = new \ReflectionClass($class);
            $lookupKey = $refl->getFileName() && preg_match('/^namespace ([^;\\\\\s]++)[;\\\\]/m', @file_get_contents($refl->getFileName()) ?: '', $m) ? $m[1] : '';
        } else {
            $lookupKey = $class;
        }

        if (\is_array(self::$namespaceRemappings)) {
            $mappedNamespace = $lookupKey;
            while (!isset(self::$namespaceRemappings[$mappedNamespace]) && false !== $pos = strrpos($mappedNamespace, '\\')) {
                $mappedNamespace = substr($mappedNamespace, 0, $pos);
            }


Review comment (performance):
```suggestion
        if (isset(self::$shortNamespacesCache[$class])) {
            // early return + remove that buildShortNamespaceEntry method
```

Code after:

    /**
     * `class_implements` includes interfaces from the parents so we have to manually exclude them.
     *
     * @return string[]
     */
    private function getOwnInterfaces(string $class, ?string $parent): array
    {
        $ownInterfaces = class_implements($class, false);

        if ($parent) {
            foreach (class_implements($parent, false) as $interface) {
                unset($ownInterfaces[$interface]);
            }
        }

        foreach ($ownInterfaces as $interface) {
            foreach (class_implements($interface) as $interface) {
                unset($ownInterfaces[$interface]);
            }
        }

        return $ownInterfaces;
    }

    /**
     * @param string $class The class being loaded and inspected for deprecation violations
     * @param string $use   The parent class, interface, or trait it extends, implements, or uses
     */
    private function areFromTheSameVendor(string $class, string $use): bool
    {
        $vendor = self::$vendorPrefixCache[$class] ?? $this->getVendorEntry($class);

        return true === $vendor || $vendor === (self::$vendorPrefixCache[$use] ?? $this->getVendorEntry($use));
    }

    /**
     * Returns the vendor string for a class, computing and caching it if necessary. Takes
     * remapping into account, see {@see enable()}.
     *
     * @return true|string the vendor prefix to consider; true when the class is in the root namespace
     *                     (matches every vendor)
     */
    private function getVendorEntry(string $class): bool|string
    {
        if (isset(self::$vendorPrefixCache[$class])) {
            return self::$vendorPrefixCache[$class];
        }

        // Anonymous classes carry a file path in their internal name instead of a namespace,
        // so the vendor prefix must be derived from the namespace declared in their source file.