From 0c44174564005e07ddf9667abbb4a139ad39b4e2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 9 Aug 2019 23:46:25 +0800 Subject: [PATCH 1/3] :art: Remove redundant slice assignment --- extension/table.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/extension/table.go b/extension/table.go index a5bfce6..a11f89e 100644 --- a/extension/table.go +++ b/extension/table.go @@ -116,24 +116,12 @@ func (b *tableParagraphTransformer) parseDelimiter(segment text.Segment, reader var alignments []ast.Alignment for _, col := range cols { if tableDelimLeft.Match(col) { - if alignments == nil { - alignments = []ast.Alignment{} - } alignments = append(alignments, ast.AlignLeft) } else if tableDelimRight.Match(col) { - if alignments == nil { - alignments = []ast.Alignment{} - } alignments = append(alignments, ast.AlignRight) } else if tableDelimCenter.Match(col) { - if alignments == nil { - alignments = []ast.Alignment{} - } alignments = append(alignments, ast.AlignCenter) } else if tableDelimNone.Match(col) { - if alignments == nil { - alignments = []ast.Alignment{} - } alignments = append(alignments, ast.AlignNone) } else { return nil From 008c25847142428897bf4744d9f5b4e82f9e739b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 9 Aug 2019 23:48:38 +0800 Subject: [PATCH 2/3] :recycle: Simplify logic --- util/util.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/util/util.go b/util/util.go index de8cd0a..bcaa51b 100644 --- a/util/util.go +++ b/util/util.go @@ -79,10 +79,9 @@ func ReadWhile(source []byte, index [2]int, pred func(byte) bool) (int, bool) { // IsBlank returns true if the given string is all space characters. func IsBlank(bs []byte) bool { for _, b := range bs { - if IsSpace(b) { - continue + if !IsSpace(b) { + return false } - return false } return true } From e7035b1993d7c0803ccf610c48fa35825fce407e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 10 Aug 2019 00:39:46 +0800 Subject: [PATCH 3/3] :recycle: Remove redundant check --- extension/table.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extension/table.go b/extension/table.go index a11f89e..8ae999b 100644 --- a/extension/table.go +++ b/extension/table.go @@ -48,10 +48,8 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text. table := ast.NewTable() table.Alignments = alignments table.AppendChild(table, ast.NewTableHeader(header)) - if lines.Len() > 2 { - for i := 2; i < lines.Len(); i++ { - table.AppendChild(table, b.parseRow(lines.At(i), alignments, false, reader)) - } + for i := 2; i < lines.Len(); i++ { + table.AppendChild(table, b.parseRow(lines.At(i), alignments, false, reader)) } node.Parent().InsertBefore(node.Parent(), node, table) node.Parent().RemoveChild(node.Parent(), node)