'Perform toc link transforms to alleviate slow loading.'

def workaround_sony_quirks(self):

    from calibre.ebooks.oeb.base import urldefrag, XPath
    from calibre.ebooks.oeb.polish.toc import item_at_top
    def frag_is_at_top(root, frag):
        elem = XPath(('//*[@id="%s"    or    @name="%s"]' % (frag, frag)))(root)
        if elem:
            elem = elem[0]
        else:
            return False
        return item_at_top(elem)
    def simplify_toc_entry(toc):
        if toc.href:
            (href, frag) = urldefrag(toc.href)
            if frag:
                for x in self.oeb.spine:
                    if (x.href == href):
                        if frag_is_at_top(x.data, frag):
                            self.log.debug('Removing    anchor    from    TOC    href:', ((href + '#') + frag))
                            toc.href = href
                        break
        for x in toc:
            simplify_toc_entry(x)
    if self.oeb.toc:
        simplify_toc_entry(self.oeb.toc)
