diff options
| author | ruki <[email protected]> | 2022-11-18 00:45:35 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-11-18 00:45:35 +0800 |
| commit | ea21365296e8b6724dea12bc6416e432bf6e4aa0 (patch) | |
| tree | fc4e3c228a55eb06e1d9a70f3382e4a9da109627 | |
| parent | 4e957f84115b29834484662f9a6e41d63b3ad711 (diff) | |
format code
| -rw-r--r-- | xmake/modules/net/fasturl.lua | 27 |
1 files changed, 1 insertions, 26 deletions
diff --git a/xmake/modules/net/fasturl.lua b/xmake/modules/net/fasturl.lua index b914624db..1849d4784 100644 --- a/xmake/modules/net/fasturl.lua +++ b/xmake/modules/net/fasturl.lua @@ -21,53 +21,31 @@ -- imports import("ping") --- parse host from url +-- http[s]://xxx.com/.. or [email protected]:xxx/xxx.git function _parse_host(url) - - -- init host cache _g._URLHOSTS = _g._URLHOSTS or {} - - -- http[s]://xxx.com/.. or [email protected]:xxx/xxx.git local host = _g._URLHOSTS[url] or url:match("://(.-)/") or url:match("@(.-):") - - -- save to cache _g._URLHOSTS[url] = host - - -- ok return host end --- add urls function add(urls) - - -- get current ping info local pinginfo = _g._PINGINFO or {} - - -- add ping hosts _g._PINGHOSTS = _g._PINGHOSTS or {} for _, url in ipairs(urls) do - - -- parse host local host = _parse_host(url) - - -- this host has not been tested? if host and not pinginfo[host] then table.insert(_g._PINGHOSTS, host) end end end --- sort urls function sort(urls) -- ping hosts local pinghosts = table.unique(_g._PINGHOSTS or {}) if pinghosts and #pinghosts > 0 then - - -- ping them and test speed, enable cache by default local pinginfo = ping(pinghosts) - - -- merge to ping info _g._PINGINFO = table.join(_g._PINGINFO or {}, pinginfo) end @@ -79,10 +57,7 @@ function sort(urls) return a < b end) - -- clear hosts _g._PINGHOSTS = {} - - -- ok return urls end |
