perf($compile): refactor publicLinkFn to simplify the code and use 'for in' loop