From 3b1964e9df5f465ed2efbb7e23be7d9ed7b19ef4 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 14 Jul 2019 22:26:21 +0200 Subject: [PATCH] migrate remaining code to the new maps --- examples/word_counter/word_counter.v | 5 +---- vlib/builtin/map.v | 2 +- vlib/http/http_mac.v | 4 +--- vlib/http/http_win.v | 5 +---- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/word_counter/word_counter.v b/examples/word_counter/word_counter.v index 1cf3e469df..82de0d4d61 100644 --- a/examples/word_counter/word_counter.v +++ b/examples/word_counter/word_counter.v @@ -26,10 +26,7 @@ fn main() { m[key] = m[key] + 1// TODO m[key]++ } // Sort the keys - mut keys := []string - for e in m.entries { - keys << e.key - } + mut keys := m.keys() keys.sort() // Print the map for key in keys { diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index bbc55a1916..5eafc1c13b 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -202,7 +202,7 @@ pub fn (m map_string) str() string { } // TODO use bytes buffer mut s := '{\n' - //for entry in m.entries { + //for key, val in m { //val := m[entry.key] //s += ' "$entry.key" => "$val"\n' //} diff --git a/vlib/http/http_mac.v b/vlib/http/http_mac.v index 66698a7d6b..9ec30a8961 100644 --- a/vlib/http/http_mac.v +++ b/vlib/http/http_mac.v @@ -124,9 +124,7 @@ fn (req &Request) do() Response { // Add request headers mut hlist := &C.curl_slist{!} // for i, h := range req.headers { - for entry in req.headers.entries { - key := entry.key - val := req.headers[key] + for key, val in req.headers { h := '$key: $val' hlist = C.curl_slist_append(hlist, h.cstr()) } diff --git a/vlib/http/http_win.v b/vlib/http/http_win.v index f4ac2bf200..a4669f7966 100644 --- a/vlib/http/http_win.v +++ b/vlib/http/http_win.v @@ -42,10 +42,7 @@ fn (req &Request) do() Response { mut headers := '' mut resp_headers := '' // for header in req.headers { - for entry in req.headers.entries { - // headers += '$header\r\n' - key := entry.key - val := req.headers[key] + for key, val in req.headers { headers += '$key: $val\r\n' } if req.typ == 'POST' {