Skip to content

Commit

Permalink
Add string interning to assets and symbols
Browse files Browse the repository at this point in the history
For #84. Update static assets and symbols.
  • Loading branch information
sonvister committed Apr 6, 2018
1 parent 428c07c commit a7277db
Show file tree
Hide file tree
Showing 6 changed files with 447 additions and 447 deletions.
6 changes: 3 additions & 3 deletions samples/BinanceCodeGenerator/Asset.template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static Asset()
// <<insert asset definitions>>

// Redirect (BCH) Bitcoin Cash (BCC = BitConnect)
{ "BCH", BCC }
{ string.Intern("BCH"), BCC }

This comment has been minimized.

Copy link
@sguryev

sguryev Apr 7, 2018

All literals are interned automatically: https://stackoverflow.com/a/8692317/1521008

};
}
catch (Exception e)
Expand All @@ -103,7 +103,7 @@ public Asset(string symbol, int precision)
if (string.IsNullOrWhiteSpace(symbol))
throw new ArgumentNullException(nameof(symbol));

Symbol = symbol.ToUpperInvariant();
Symbol = string.Intern(symbol.ToUpperInvariant());
Precision = precision;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ internal static void UpdateCache(IEnumerable<Symbol> symbols)
// Update existing and add any new assets.
foreach (var asset in assets)
{
Cache[asset] = asset;
Cache[string.Intern(asset)] = asset;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions samples/BinanceCodeGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static async Task Main()

foreach(var symbol in symbols)
{
lines.Insert(index++, $" {{ \"{symbol}\", {symbol.BaseAsset}_{symbol.QuoteAsset} }},");
lines.Insert(index++, $" {{ string.Intern(\"{symbol}\"), {symbol.BaseAsset}_{symbol.QuoteAsset} }},");
}

// Save the generated source code (replacing original).
Expand Down Expand Up @@ -104,7 +104,7 @@ private static async Task Main()

foreach (var asset in assets)
{
lines.Insert(index++, $" {{ \"{asset}\", {asset} }},");
lines.Insert(index++, $" {{ string.Intern(\"{asset}\"), {asset} }},");
}

// Save the generated source code (replacing original).
Expand Down
12 changes: 6 additions & 6 deletions samples/BinanceCodeGenerator/Symbol.template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ static Symbol()
// <<insert symbol definitions>>

// Redirect (BCH) Bitcoin Cash (BCC = BitConnect)
{ "BCHUSDT", BCC_USDT },
{ "BCHBNB", BCC_BNB },
{ "BCHBTC", BCC_BTC },
{ "BCHETH", BCC_ETH }
{ string.Intern("BCHUSDT"), BCC_USDT },

This comment has been minimized.

Copy link
@sguryev

sguryev Apr 7, 2018

All literals are interned automatically: https://stackoverflow.com/a/8692317/1521008

{ string.Intern("BCHBNB"), BCC_BNB },
{ string.Intern("BCHBTC"), BCC_BTC },
{ string.Intern("BCHETH"), BCC_ETH }
};
}
catch (Exception e)
Expand Down Expand Up @@ -167,7 +167,7 @@ public Symbol(SymbolStatus status, Asset baseAsset, Asset quoteAsset, InclusiveR
IsIcebergAllowed = isIcebergAllowed;
OrderTypes = orderTypes;

_symbol = $"{baseAsset}{quoteAsset}";
_symbol = string.Intern($"{baseAsset}{quoteAsset}");
}

#endregion Constructors
Expand Down Expand Up @@ -237,7 +237,7 @@ public static void UpdateCache(IEnumerable<Symbol> symbols)
// ReSharper disable once PossibleMultipleEnumeration
foreach (var symbol in symbols)
{
Cache[symbol] = symbol;
Cache[string.Intern(symbol)] = symbol;
}
}

Expand Down
254 changes: 127 additions & 127 deletions src/Binance/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class Asset : IComparable<Asset>, IEquatable<Asset>
/// <summary>
/// When the assets were last updated.
/// </summary>
public static readonly long LastUpdateAt = 1522861060011;
public static readonly long LastUpdateAt = 1523044545253;

public static readonly Asset ADA = new Asset("ADA", 8);
public static readonly Asset ADX = new Asset("ADX", 8);
Expand Down Expand Up @@ -203,132 +203,132 @@ static Asset()

Cache = new Dictionary<string, Asset>
{
{ "ADA", ADA },
{ "ADX", ADX },
{ "AE", AE },
{ "AION", AION },
{ "AMB", AMB },
{ "APPC", APPC },
{ "ARK", ARK },
{ "ARN", ARN },
{ "AST", AST },
{ "BAT", BAT },
{ "BCC", BCC },
{ "BCD", BCD },
{ "BCPT", BCPT },
{ "BLZ", BLZ },
{ "BNB", BNB },
{ "BNT", BNT },
{ "BQX", BQX },
{ "BRD", BRD },
{ "BTC", BTC },
{ "BTG", BTG },
{ "BTS", BTS },
{ "CDT", CDT },
{ "CHAT", CHAT },
{ "CMT", CMT },
{ "CND", CND },
{ "CTR", CTR },
{ "DASH", DASH },
{ "DGD", DGD },
{ "DLT", DLT },
{ "DNT", DNT },
{ "EDO", EDO },
{ "ELF", ELF },
{ "ENG", ENG },
{ "ENJ", ENJ },
{ "EOS", EOS },
{ "ETC", ETC },
{ "ETH", ETH },
{ "EVX", EVX },
{ "FUEL", FUEL },
{ "FUN", FUN },
{ "GAS", GAS },
{ "GRS", GRS },
{ "GTO", GTO },
{ "GVT", GVT },
{ "GXS", GXS },
{ "HSR", HSR },
{ "ICN", ICN },
{ "ICX", ICX },
{ "INS", INS },
{ "IOST", IOST },
{ "IOTA", IOTA },
{ "KMD", KMD },
{ "KNC", KNC },
{ "LEND", LEND },
{ "LINK", LINK },
{ "LRC", LRC },
{ "LSK", LSK },
{ "LTC", LTC },
{ "LUN", LUN },
{ "MANA", MANA },
{ "MCO", MCO },
{ "MDA", MDA },
{ "MOD", MOD },
{ "MTH", MTH },
{ "MTL", MTL },
{ "NANO", NANO },
{ "NAV", NAV },
{ "NCASH", NCASH },
{ "NEBL", NEBL },
{ "NEO", NEO },
{ "NULS", NULS },
{ "OAX", OAX },
{ "OMG", OMG },
{ "ONT", ONT },
{ "OST", OST },
{ "PIVX", PIVX },
{ "POA", POA },
{ "POE", POE },
{ "POWR", POWR },
{ "PPT", PPT },
{ "QLC", QLC },
{ "QSP", QSP },
{ "QTUM", QTUM },
{ "RCN", RCN },
{ "RDN", RDN },
{ "REQ", REQ },
{ "RLC", RLC },
{ "RPX", RPX },
{ "SALT", SALT },
{ "SNGLS", SNGLS },
{ "SNM", SNM },
{ "SNT", SNT },
{ "STEEM", STEEM },
{ "STORJ", STORJ },
{ "STORM", STORM },
{ "STRAT", STRAT },
{ "SUB", SUB },
{ "SYS", SYS },
{ "TNB", TNB },
{ "TNT", TNT },
{ "TRIG", TRIG },
{ "TRX", TRX },
{ "USDT", USDT },
{ "VEN", VEN },
{ "VIA", VIA },
{ "VIB", VIB },
{ "VIBE", VIBE },
{ "WABI", WABI },
{ "WAN", WAN },
{ "WAVES", WAVES },
{ "WINGS", WINGS },
{ "WPR", WPR },
{ "WTC", WTC },
{ "XEM", XEM },
{ "XLM", XLM },
{ "XMR", XMR },
{ "XRP", XRP },
{ "XVG", XVG },
{ "XZC", XZC },
{ "YOYO", YOYO },
{ "ZEC", ZEC },
{ "ZIL", ZIL },
{ "ZRX", ZRX },
{ string.Intern("ADA"), ADA },
{ string.Intern("ADX"), ADX },
{ string.Intern("AE"), AE },
{ string.Intern("AION"), AION },
{ string.Intern("AMB"), AMB },
{ string.Intern("APPC"), APPC },
{ string.Intern("ARK"), ARK },
{ string.Intern("ARN"), ARN },
{ string.Intern("AST"), AST },
{ string.Intern("BAT"), BAT },
{ string.Intern("BCC"), BCC },
{ string.Intern("BCD"), BCD },
{ string.Intern("BCPT"), BCPT },
{ string.Intern("BLZ"), BLZ },
{ string.Intern("BNB"), BNB },
{ string.Intern("BNT"), BNT },
{ string.Intern("BQX"), BQX },
{ string.Intern("BRD"), BRD },
{ string.Intern("BTC"), BTC },
{ string.Intern("BTG"), BTG },
{ string.Intern("BTS"), BTS },
{ string.Intern("CDT"), CDT },
{ string.Intern("CHAT"), CHAT },
{ string.Intern("CMT"), CMT },
{ string.Intern("CND"), CND },
{ string.Intern("CTR"), CTR },
{ string.Intern("DASH"), DASH },
{ string.Intern("DGD"), DGD },
{ string.Intern("DLT"), DLT },
{ string.Intern("DNT"), DNT },
{ string.Intern("EDO"), EDO },
{ string.Intern("ELF"), ELF },
{ string.Intern("ENG"), ENG },
{ string.Intern("ENJ"), ENJ },
{ string.Intern("EOS"), EOS },
{ string.Intern("ETC"), ETC },
{ string.Intern("ETH"), ETH },
{ string.Intern("EVX"), EVX },
{ string.Intern("FUEL"), FUEL },
{ string.Intern("FUN"), FUN },
{ string.Intern("GAS"), GAS },
{ string.Intern("GRS"), GRS },
{ string.Intern("GTO"), GTO },
{ string.Intern("GVT"), GVT },
{ string.Intern("GXS"), GXS },
{ string.Intern("HSR"), HSR },
{ string.Intern("ICN"), ICN },
{ string.Intern("ICX"), ICX },
{ string.Intern("INS"), INS },
{ string.Intern("IOST"), IOST },
{ string.Intern("IOTA"), IOTA },
{ string.Intern("KMD"), KMD },
{ string.Intern("KNC"), KNC },
{ string.Intern("LEND"), LEND },
{ string.Intern("LINK"), LINK },
{ string.Intern("LRC"), LRC },
{ string.Intern("LSK"), LSK },
{ string.Intern("LTC"), LTC },
{ string.Intern("LUN"), LUN },
{ string.Intern("MANA"), MANA },
{ string.Intern("MCO"), MCO },
{ string.Intern("MDA"), MDA },
{ string.Intern("MOD"), MOD },
{ string.Intern("MTH"), MTH },
{ string.Intern("MTL"), MTL },
{ string.Intern("NANO"), NANO },
{ string.Intern("NAV"), NAV },
{ string.Intern("NCASH"), NCASH },
{ string.Intern("NEBL"), NEBL },
{ string.Intern("NEO"), NEO },
{ string.Intern("NULS"), NULS },
{ string.Intern("OAX"), OAX },
{ string.Intern("OMG"), OMG },
{ string.Intern("ONT"), ONT },
{ string.Intern("OST"), OST },
{ string.Intern("PIVX"), PIVX },
{ string.Intern("POA"), POA },
{ string.Intern("POE"), POE },
{ string.Intern("POWR"), POWR },
{ string.Intern("PPT"), PPT },
{ string.Intern("QLC"), QLC },
{ string.Intern("QSP"), QSP },
{ string.Intern("QTUM"), QTUM },
{ string.Intern("RCN"), RCN },
{ string.Intern("RDN"), RDN },
{ string.Intern("REQ"), REQ },
{ string.Intern("RLC"), RLC },
{ string.Intern("RPX"), RPX },
{ string.Intern("SALT"), SALT },
{ string.Intern("SNGLS"), SNGLS },
{ string.Intern("SNM"), SNM },
{ string.Intern("SNT"), SNT },
{ string.Intern("STEEM"), STEEM },
{ string.Intern("STORJ"), STORJ },
{ string.Intern("STORM"), STORM },
{ string.Intern("STRAT"), STRAT },
{ string.Intern("SUB"), SUB },
{ string.Intern("SYS"), SYS },
{ string.Intern("TNB"), TNB },
{ string.Intern("TNT"), TNT },
{ string.Intern("TRIG"), TRIG },
{ string.Intern("TRX"), TRX },
{ string.Intern("USDT"), USDT },
{ string.Intern("VEN"), VEN },
{ string.Intern("VIA"), VIA },
{ string.Intern("VIB"), VIB },
{ string.Intern("VIBE"), VIBE },
{ string.Intern("WABI"), WABI },
{ string.Intern("WAN"), WAN },
{ string.Intern("WAVES"), WAVES },
{ string.Intern("WINGS"), WINGS },
{ string.Intern("WPR"), WPR },
{ string.Intern("WTC"), WTC },
{ string.Intern("XEM"), XEM },
{ string.Intern("XLM"), XLM },
{ string.Intern("XMR"), XMR },
{ string.Intern("XRP"), XRP },
{ string.Intern("XVG"), XVG },
{ string.Intern("XZC"), XZC },
{ string.Intern("YOYO"), YOYO },
{ string.Intern("ZEC"), ZEC },
{ string.Intern("ZIL"), ZIL },
{ string.Intern("ZRX"), ZRX },

// Redirect (BCH) Bitcoin Cash (BCC = BitConnect)
{ "BCH", BCC }
{ string.Intern("BCH"), BCC }
};
}
catch (Exception e)
Expand All @@ -347,7 +347,7 @@ public Asset(string symbol, int precision)
if (string.IsNullOrWhiteSpace(symbol))
throw new ArgumentNullException(nameof(symbol));

Symbol = symbol.ToUpperInvariant();
Symbol = string.Intern(symbol.ToUpperInvariant());
Precision = precision;
}

Expand Down Expand Up @@ -440,7 +440,7 @@ internal static void UpdateCache(IEnumerable<Symbol> symbols)
// Update existing and add any new assets.
foreach (var asset in assets)
{
Cache[asset] = asset;
Cache[string.Intern(asset)] = asset;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Binance/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ internal static string FormatSymbol(this string symbol)
{
Throw.IfNullOrWhiteSpace(symbol);

return symbol.Trim()
return string.Intern(symbol.Trim()
.Replace(" ", string.Empty)
.Replace("-", string.Empty)
.Replace("_", string.Empty)
.Replace("/", string.Empty)
.ToUpperInvariant();
.ToUpperInvariant());
}

/// <summary>
Expand Down
Loading

0 comments on commit a7277db

Please sign in to comment.