PDF-Writer icon indicating copy to clipboard operation
PDF-Writer copied to clipboard

'groupToShift' serves no purpose

Open theSundayProgrammer opened this issue 6 years ago • 3 comments

In the following function 'groupToShift' serves no purpose as the data is not saved or used elsewhere

Byte* CharStringType2Interpreter::InterpretRoll(Byte* inProgramCounter)
{
EStatusCode status = mImplementationHelper->Type2Roll(mOperandStack);
if(status != PDFHummus::eSuccess)
	return NULL;

CharStringOperand valueA;
CharStringOperand valueB;

valueB = mOperandStack.back();
mOperandStack.pop_back();
valueA = mOperandStack.back();
mOperandStack.pop_back();

long shiftAmount = (valueB.IsInteger ? valueB.IntegerValue : (long)valueB.RealValue);
long itemsCount = (valueA.IsInteger ? valueA.IntegerValue : (long)valueA.RealValue);

CharStringOperandList groupToShift;

for(long i=0; i < itemsCount;++i)
{
	groupToShift.push_front(mOperandStack.back());
	mOperandStack.pop_back();
}

if(shiftAmount > 0)
{
	for(long j=0; j < shiftAmount;++j)
	{
		groupToShift.push_front(groupToShift.back());
		groupToShift.pop_back();
	}
}
else
{
	for(long j=0; j < -shiftAmount;++j)
	{
		groupToShift.push_back(groupToShift.front());
		groupToShift.pop_front();
	}

}

for(long i=0; i < itemsCount;++i)
{
	mOperandStack.push_back(mOperandStack.front());
	mOperandStack.pop_front();
}

return inProgramCounter;
}

theSundayProgrammer avatar Sep 25 '18 23:09 theSundayProgrammer

... besides it is better to use std::rotate rather than implement it as in

if (shiftAmount > 0) 
   std::rotate(groupToShift.begin(), groupToShift.end(), groupToShift.end() - shiftAmount);       
else if (shiftAmount < 0)
   std::rotate(groupToShift.begin(), groupToShift.end(), groupToShift.begin() - shiftAmount);

theSundayProgrammer avatar Sep 26 '18 00:09 theSundayProgrammer

I stand corrected. list::iterator supports increment/decrement by one only. Besides the actual parameters are in the wrong order. Both minor fixes, if I could tell the purpose of the function.

theSundayProgrammer avatar Sep 27 '18 23:09 theSundayProgrammer

Closed by mistake

theSundayProgrammer avatar Sep 28 '18 06:09 theSundayProgrammer