Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Commit

Permalink
Convert StringBuilder instance to use StringBuilderCache
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Apr 29, 2016
1 parent ed73f0f commit 2939228
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/ServiceStack.Redis/RedisClient_Admin.cs
Expand Up @@ -32,7 +32,7 @@ public RedisText GetServerRoleInfo()

public string GetConfig(string configItem)
{
var sb = new StringBuilder();
var sb = StringBuilderCache.Allocate();
var byteArray = base.ConfigGet(configItem);
const int startAt = 1; //skip repeating config name
for (var i = startAt; i < byteArray.Length; i++)
Expand All @@ -43,7 +43,7 @@ public string GetConfig(string configItem)

sb.Append(bytes.FromUtf8Bytes());
}
return sb.ToString();
return StringBuilderCache.ReturnAndFree(sb);
}

public void SaveConfig()
Expand Down
6 changes: 4 additions & 2 deletions src/ServiceStack.Redis/RedisEndpoint.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using ServiceStack.IO;
using ServiceStack.Text;

namespace ServiceStack.Redis
{
Expand Down Expand Up @@ -45,7 +47,7 @@ public RedisEndpoint(string host, int port, string password = null, long db = Re

public override string ToString()
{
var sb = new StringBuilder();
var sb = StringBuilderCache.Allocate();
sb.AppendFormat("{0}:{1}", Host, Port);

var args = new List<string>();
Expand Down Expand Up @@ -73,7 +75,7 @@ public override string ToString()
if (args.Count > 0)
sb.Append("?").Append(string.Join("&", args));

return sb.ToString();
return StringBuilderCache.ReturnAndFree(sb);
}

protected bool Equals(RedisEndpoint other)
Expand Down
8 changes: 4 additions & 4 deletions src/ServiceStack.Redis/RedisNativeClient_Utils.cs
Expand Up @@ -203,7 +203,7 @@ public virtual void OnConnected()

protected string ReadLine()
{
var sb = new StringBuilder();
var sb = StringBuilderCache.Allocate();

int c;
while ((c = Bstream.ReadByte()) != -1)
Expand All @@ -214,7 +214,7 @@ protected string ReadLine()
break;
sb.Append((char)c);
}
return sb.ToString();
return StringBuilderCache.ReturnAndFree(sb);
}

public bool HasConnected
Expand Down Expand Up @@ -680,7 +680,7 @@ protected void Log(string fmt, params object[] args)

protected void CmdLog(byte[][] args)
{
var sb = new StringBuilder();
var sb = StringBuilderCache.Allocate();
foreach (var arg in args)
{
var strArg = arg.FromUtf8Bytes();
Expand All @@ -694,7 +694,7 @@ protected void CmdLog(byte[][] args)
if (sb.Length > 100)
break;
}
this.lastCommand = sb.ToString();
this.lastCommand = StringBuilderCache.ReturnAndFree(sb);
if (this.lastCommand.Length > 100)
{
this.lastCommand = this.lastCommand.Substring(0, 100) + "...";
Expand Down
5 changes: 3 additions & 2 deletions src/ServiceStack.Redis/RedisPubSubServer.cs
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using System.Threading;
using ServiceStack.Logging;
using ServiceStack.Text;

namespace ServiceStack.Redis
{
Expand Down Expand Up @@ -523,15 +524,15 @@ public string GetStatus()

public string GetStatsDescription()
{
var sb = new StringBuilder();
var sb = StringBuilderCache.Allocate();
sb.AppendLine("===============");
sb.AppendLine("Current Status: " + GetStatus());
sb.AppendLine("Times Started: " + Interlocked.CompareExchange(ref timesStarted, 0, 0));
sb.AppendLine("Num of Errors: " + Interlocked.CompareExchange(ref noOfErrors, 0, 0));
sb.AppendLine("Num of Continuous Errors: " + Interlocked.CompareExchange(ref noOfContinuousErrors, 0, 0));
sb.AppendLine("Last ErrorMsg: " + lastExMsg);
sb.AppendLine("===============");
return sb.ToString();
return StringBuilderCache.ReturnAndFree(sb);
}

public virtual void Dispose()
Expand Down

0 comments on commit 2939228

Please sign in to comment.