Skip to content

GSHorizontalTypesetter improvements: Add Fast Path for Simple Rectangular Containers #409

@IOOI-SqAR

Description

@IOOI-SqAR

I asked the Kimi AI how to further improve GSHorizontalTypesetter. Here is what it came up with:

https://www.kimi.com/share/19d34cdb-8242-8fc9-8000-00001fd46e3b

Add Fast Path for Simple Rectangular Containers

The TODO comment mentions this optimization. For the common case of a simple rectangular text container without exclusion paths, bypass the expensive line fragment rect building:

- (BOOL) _useSimpleRectangularLayout: (NSRect)proposedRect
                          lineHeight: (CGFloat)lineHeight
{
    if (![currentTextContainer isSimpleRectangularTextContainer])
        return NO;
    
    NSSize containerSize = [currentTextContainer containerSize];
    NSRect simpleRect = proposedRect;
    
    // Single rectangle for the entire width
    if (lineFragmentCount == 0) {
        lineFragmentCapacity = MAX(lineFragmentCapacity, 2);
        lineFragments = realloc(lineFragments, sizeof(LineFragment) * lineFragmentCapacity);
    }
    
    lineFragments[0].rect = simpleRect;
    lineFragmentCount = 1;
    
    // Skip the expensive lineFragmentRectForProposedRect: loop
    return YES;
}

I would say we should address this after fixing the line wrap bug first (has been #382 which is closed now (but the issue is not fixed yet))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions