From 5b2fb1b893850a20a483145b676af75eaad51a5d Mon Sep 17 00:00:00 2001 From: choueric Date: Sat, 10 Jun 2017 22:24:27 +0800 Subject: [PATCH] use map[string]struct{} as a set. Use map[string]struct{} instead of map[string]bool to implement a set and reduce memory space. --- inline.go | 4 ++-- markdown.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inline.go b/inline.go index ca22af5..4483b8f 100644 --- a/inline.go +++ b/inline.go @@ -488,7 +488,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { } p.notes = append(p.notes, ref) - p.notesRecord[string(ref.link)] = true + p.notesRecord[string(ref.link)] = struct{}{} link = ref.link title = ref.title @@ -502,7 +502,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { if t == linkDeferredFootnote && !p.isFootnote(lr) { lr.noteId = len(p.notes) + 1 p.notes = append(p.notes, lr) - p.notesRecord[string(lr.link)] = true + p.notesRecord[string(lr.link)] = struct{}{} } // keep link and title from reference diff --git a/markdown.go b/markdown.go index ee03fda..1722a73 100644 --- a/markdown.go +++ b/markdown.go @@ -219,7 +219,7 @@ type parser struct { // presence. If a ref is also a footnote, it's stored both in refs and here // in notes. Slice is nil if footnotes not enabled. notes []*reference - notesRecord map[string]bool + notesRecord map[string]struct{} } func (p *parser) getRef(refid string) (ref *reference, found bool) { @@ -382,7 +382,7 @@ func MarkdownOptions(input []byte, renderer Renderer, opts Options) []byte { if extensions&EXTENSION_FOOTNOTES != 0 { p.notes = make([]*reference, 0) - p.notesRecord = make(map[string]bool) + p.notesRecord = make(map[string]struct{}) } first := firstPass(p, input)