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
parent
8c89af6200
commit
5b2fb1b893
|
@ -488,7 +488,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.notes = append(p.notes, ref)
|
p.notes = append(p.notes, ref)
|
||||||
p.notesRecord[string(ref.link)] = true
|
p.notesRecord[string(ref.link)] = struct{}{}
|
||||||
|
|
||||||
link = ref.link
|
link = ref.link
|
||||||
title = ref.title
|
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) {
|
if t == linkDeferredFootnote && !p.isFootnote(lr) {
|
||||||
lr.noteId = len(p.notes) + 1
|
lr.noteId = len(p.notes) + 1
|
||||||
p.notes = append(p.notes, lr)
|
p.notes = append(p.notes, lr)
|
||||||
p.notesRecord[string(lr.link)] = true
|
p.notesRecord[string(lr.link)] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep link and title from reference
|
// keep link and title from reference
|
||||||
|
|
|
@ -219,7 +219,7 @@ type parser struct {
|
||||||
// presence. If a ref is also a footnote, it's stored both in refs and here
|
// 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.
|
// in notes. Slice is nil if footnotes not enabled.
|
||||||
notes []*reference
|
notes []*reference
|
||||||
notesRecord map[string]bool
|
notesRecord map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) getRef(refid string) (ref *reference, found bool) {
|
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 {
|
if extensions&EXTENSION_FOOTNOTES != 0 {
|
||||||
p.notes = make([]*reference, 0)
|
p.notes = make([]*reference, 0)
|
||||||
p.notesRecord = make(map[string]bool)
|
p.notesRecord = make(map[string]struct{})
|
||||||
}
|
}
|
||||||
|
|
||||||
first := firstPass(p, input)
|
first := firstPass(p, input)
|
||||||
|
|
Loading…
Reference in New Issue