```python
def shed_tail(text: str, piece: str) -> str:
    """Remove occurrences of piece from the end of text as long as it matches."""
    if not piece:
        return text
    
    text_len = len(text)
    piece_len = len(piece)
    
    while text_len >= piece_len and text[text_len - piece_len:] == piece:
        text = text[:text_len - piece_len]
        text_len = len(text)
        
    return text
```