From 4995379a8e3276553f6d41d62e6ed5ee4f1f0a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Wed, 24 Nov 2010 18:54:12 +0100 Subject: [PATCH] preformat: use bytes.Buffer instead of concatenating strings --- markdown.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/markdown.go b/markdown.go index 7027980..4639dec 100644 --- a/markdown.go +++ b/markdown.go @@ -21,6 +21,7 @@ package markdown import ( "strings" + "bytes" ) // Markdown Extensions: @@ -115,16 +116,17 @@ func preformat(text string) (s string) { charstotab := TABSTOP i0 := 0 + b := bytes.NewBuffer(make([]byte, 0, len(text)+256)) for i, _ := range text { switch text[i] { case '\t': - s += text[i0:i] + b.WriteString(text[i0:i]) for ; charstotab > 0; charstotab-- { - s += " " + b.WriteByte(' ') } i0 = i + 1 case '\n': - s += text[i0 : i+1] + b.WriteString(text[i0 : i+1]) i0 = i + 1 charstotab = TABSTOP default: @@ -134,5 +136,7 @@ func preformat(text string) (s string) { charstotab = TABSTOP } } - return s + text[i0:] + "\n\n" + b.WriteString(text[i0:]) + b.WriteString("\n\n") + return b.String() }