From 365cffa6a49a41dc4d48572b1f2e0cefe7320df9 Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Wed, 26 May 2010 01:41:44 +0200 Subject: [PATCH] Updated code to conform with more recent go idioms. --- src/atom.go | 1 - src/channel.go | 21 ++++++++------------- src/feed.go | 10 ++++------ src/feed_test.go | 10 ++++++---- src/item.go | 20 ++++++++------------ 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/atom.go b/src/atom.go index 062d427..335e2ff 100644 --- a/src/atom.go +++ b/src/atom.go @@ -20,7 +20,6 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) { ch.Links[i].Rel = v.GetAttr("", "rel") ch.Links[i].Type = v.GetAttr("", "type") ch.Links[i].HrefLang = v.GetAttr("", "hreflang") - } tn := node.SelectNode(ns, "subtitle") diff --git a/src/channel.go b/src/channel.go index cd24975..dd8fc12 100644 --- a/src/channel.go +++ b/src/channel.go @@ -30,20 +30,15 @@ type Channel struct { } func (this *Channel) addItem(item Item) { - slice := make([]Item, len(this.Items)+1) - for i, v := range this.Items { - slice[i] = v - } - slice[len(slice)-1] = item - this.Items = slice + c := make([]Item, len(this.Items)+1) + copy(c, this.Items) + c[len(c)-1] = item + this.Items = c } - func (this *Channel) addLink(l Link) { - slice := make([]Link, len(this.Links)+1) - for i, v := range this.Links { - slice[i] = v - } - slice[len(slice)-1] = l - this.Links = slice + c := make([]Link, len(this.Links)+1) + copy(c, this.Links) + c[len(c)-1] = l + this.Links = c } diff --git a/src/feed.go b/src/feed.go index f195fb6..337b0b5 100644 --- a/src/feed.go +++ b/src/feed.go @@ -74,12 +74,10 @@ func New(cachetimeout int, enforcecachelimit bool) *Feed { } func (this *Feed) addChannel(ch Channel) { - slice := make([]Channel, len(this.Channels)+1) - for i, v := range this.Channels { - slice[i] = v - } - slice[len(slice)-1] = ch - this.Channels = slice + c := make([]Channel, len(this.Channels)+1) + copy(c, this.Channels) + c[len(c)-1] = ch + this.Channels = c } func (this *Feed) Fetch(uri string) (err os.Error) { diff --git a/src/feed_test.go b/src/feed_test.go index 0525ac7..c46ab36 100644 --- a/src/feed_test.go +++ b/src/feed_test.go @@ -10,12 +10,14 @@ func TestFeed(t *testing.T) { "http://blog.case.edu/news/feed.atom", } + var feed *Feed + var err os.Error + for _, uri := range urilist { - feed := New(5, true) - err := feed.Fetch(uri) - if err != nil { + feed = New(5, true) + + if err = feed.Fetch(uri); err != nil { t.Errorf("%s >>> %s", uri, err) - continue } } } diff --git a/src/item.go b/src/item.go index 9826e63..b8be54e 100644 --- a/src/item.go +++ b/src/item.go @@ -21,19 +21,15 @@ type Item struct { } func (this *Item) addEnclosure(e Enclosure) { - slice := make([]Enclosure, len(this.Enclosures)+1) - for i, v := range this.Enclosures { - slice[i] = v - } - slice[len(slice)-1] = e - this.Enclosures = slice + c := make([]Enclosure, len(this.Enclosures)+1) + copy(c, this.Enclosures) + c[len(c)-1] = e + this.Enclosures = c } func (this *Item) addLink(l Link) { - slice := make([]Link, len(this.Links)+1) - for i, v := range this.Links { - slice[i] = v - } - slice[len(slice)-1] = l - this.Links = slice + c := make([]Link, len(this.Links)+1) + copy(c, this.Links) + c[len(c)-1] = l + this.Links = c }