Skip to content

Commit

Permalink
Eliminate creation of temporary strings in loops.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/xalan/java/trunk@1225442 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Michael Glavassevich committed Dec 29, 2011
1 parent ac06b3d commit 51e7b4f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/org/apache/xalan/templates/ElemNumber.java
Expand Up @@ -1219,16 +1219,17 @@ String formatNumberList(
// then append the formatToken.
else if (formatTokenizer.isLetterOrDigitAhead())
{
formatTokenString = formatToken;
final StringBuffer formatTokenStringBuffer = new StringBuffer(formatToken);

// Append the formatToken string...
// For instance [2][1][5] with a format value of "1--1. "
// should format to "2--1--5. " (I guess).
while (formatTokenizer.nextIsSep())
{
formatToken = formatTokenizer.nextToken();
formatTokenString += formatToken;
formatTokenStringBuffer.append(formatToken);
}
formatTokenString = formatTokenStringBuffer.toString();

// Record this separator, so it can be used as the
// next separator, if the next is the last.
Expand Down Expand Up @@ -1943,31 +1944,33 @@ protected String long2roman(long val, boolean prefixesAreOK)
return getZeroString();
}

String roman = "";
final String roman;
int place = 0;

if (val <= 3999L)
{
StringBuffer romanBuffer = new StringBuffer();
do
{
while (val >= m_romanConvertTable[place].m_postValue)
{
roman += m_romanConvertTable[place].m_postLetter;
romanBuffer.append(m_romanConvertTable[place].m_postLetter);
val -= m_romanConvertTable[place].m_postValue;
}

if (prefixesAreOK)
{
if (val >= m_romanConvertTable[place].m_preValue)
{
roman += m_romanConvertTable[place].m_preLetter;
romanBuffer.append(m_romanConvertTable[place].m_preLetter);
val -= m_romanConvertTable[place].m_preValue;
}
}

place++;
}
while (val > 0);
roman = romanBuffer.toString();
}
else
{
Expand Down

0 comments on commit 51e7b4f

Please sign in to comment.