public function addRouteDefinition(RouteDefinition $definition): void
    {
        $name = $definition->getName();

        if (isset($this->routesByName[$name])) {
            throw new \InvalidArgumentException("Route with name '$name' already exists");
        }

        $routeId = \count($this->routeDefinitions);
        $segments = $definition->getSegments();

        $this->routeDefinitions[$routeId] = $definition->getDefinitionCache();
        $this->routesByName[$name] = $routeId;

        if ($definition->isStatic()) {
            $this->staticRoutes[implode('/', $segments)][] = $routeId;
            return;
        }

        foreach ($segments as $i => $segment) {
            $this->segmentValues[$i][$segment][$routeId] = $routeId;

            if (!isset($this->segmentCounts[$i])) {
                $this->segmentCounts[$i] = [];
            }
        }

        $this->segmentCounts[\count($segments)][$routeId] = $routeId;
    }