use map[string]struct{} as a set.

Use map[string]struct{} instead of map[string]bool to implement a set
and reduce memory space.
pull/366/head
choueric 2017-06-10 22:24:27 +08:00
parent 8c89af6200
commit 5b2fb1b893
2 changed files with 4 additions and 4 deletions

View File

@ -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

View File

@ -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)