[Libreoffice-commits] core.git: 2 commits - sdext/source
Noel Grandin
noel at peralex.com
Fri Jun 19 01:56:35 PDT 2015
sdext/source/pdfimport/tree/drawtreevisiting.cxx | 69 ++++++++--------
sdext/source/pdfimport/wrapper/wrapper.cxx | 94 ++++++++++++++++-------
2 files changed, 102 insertions(+), 61 deletions(-)
New commits:
commit 7d69c94104ef60d4c9f08274136067b6120fa23e
Author: Noel Grandin <noel at peralex.com>
Date: Fri Jun 19 10:55:44 2015 +0200
fix older compiler
after my commit e0f3e7c007e9eeced888b491ec2698acba4bc588
"tdf#42374 some small optimisations for opening this PDF file"
Change-Id: Ib9dc0aaf3ad2afca272160a934049d89bbd54175
diff --git a/sdext/source/pdfimport/tree/drawtreevisiting.cxx b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
index 832d355..9c19aa4 100644
--- a/sdext/source/pdfimport/tree/drawtreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/drawtreevisiting.cxx
@@ -418,42 +418,43 @@ void DrawXmlOptimizer::visit( PolyPolyElement& elem, const std::list< Element* >
if( next_it == elem.Parent->Children.end() )
return;
- PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it);
- // TODO(F2): this comparison fails for OOo-generated polygons with beziers.
- if( !pNext || pNext->PolyPoly != elem.PolyPoly )
+ PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(*next_it);
+ // TODO(F2): this comparison fails for OOo-generated polygons with beziers.
+ if( !pNext || pNext->PolyPoly != elem.PolyPoly )
return;
- const GraphicsContext& rNextGC =
- m_rProcessor.getGraphicsContext( pNext->GCId );
- const GraphicsContext& rThisGC =
- m_rProcessor.getGraphicsContext( elem.GCId );
-
- if( rThisGC.BlendMode == rNextGC.BlendMode &&
- rThisGC.Flatness == rNextGC.Flatness &&
- rThisGC.Transformation == rNextGC.Transformation &&
- rThisGC.Clip == rNextGC.Clip &&
- rThisGC.FillColor.Red == rNextGC.FillColor.Red &&
- rThisGC.FillColor.Green== rNextGC.FillColor.Green &&
- rThisGC.FillColor.Blue == rNextGC.FillColor.Blue &&
- rThisGC.FillColor.Alpha== rNextGC.FillColor.Alpha &&
- pNext->Action == PATH_STROKE &&
- (elem.Action == PATH_FILL || elem.Action == PATH_EOFILL) )
- {
- GraphicsContext aGC = rThisGC;
- aGC.LineJoin = rNextGC.LineJoin;
- aGC.LineCap = rNextGC.LineCap;
- aGC.LineWidth = rNextGC.LineWidth;
- aGC.MiterLimit= rNextGC.MiterLimit;
- aGC.DashArray = rNextGC.DashArray;
- aGC.LineColor = rNextGC.LineColor;
- elem.GCId = m_rProcessor.getGCId( aGC );
-
- elem.Action |= pNext->Action;
-
- elem.Children.splice( elem.Children.end(), pNext->Children );
- elem.Parent->Children.erase( next_it );
- delete pNext;
- }
+ const GraphicsContext& rNextGC =
+ m_rProcessor.getGraphicsContext( pNext->GCId );
+ const GraphicsContext& rThisGC =
+ m_rProcessor.getGraphicsContext( elem.GCId );
+
+ if( rThisGC.BlendMode == rNextGC.BlendMode &&
+ rThisGC.Flatness == rNextGC.Flatness &&
+ rThisGC.Transformation == rNextGC.Transformation &&
+ rThisGC.Clip == rNextGC.Clip &&
+ rThisGC.FillColor.Red == rNextGC.FillColor.Red &&
+ rThisGC.FillColor.Green== rNextGC.FillColor.Green &&
+ rThisGC.FillColor.Blue == rNextGC.FillColor.Blue &&
+ rThisGC.FillColor.Alpha== rNextGC.FillColor.Alpha &&
+ pNext->Action == PATH_STROKE &&
+ (elem.Action == PATH_FILL || elem.Action == PATH_EOFILL) )
+ {
+ GraphicsContext aGC = rThisGC;
+ aGC.LineJoin = rNextGC.LineJoin;
+ aGC.LineCap = rNextGC.LineCap;
+ aGC.LineWidth = rNextGC.LineWidth;
+ aGC.MiterLimit= rNextGC.MiterLimit;
+ aGC.DashArray = rNextGC.DashArray;
+ aGC.LineColor = rNextGC.LineColor;
+ elem.GCId = m_rProcessor.getGCId( aGC );
+
+ elem.Action |= pNext->Action;
+
+ elem.Children.splice( elem.Children.end(), pNext->Children );
+ std::list< Element* > tmp;
+ tmp.splice( tmp.begin(), elem.Parent->Children, next_it, next_it);
+ delete pNext;
+ }
}
void DrawXmlOptimizer::visit( ParagraphElement& elem, const std::list< Element* >::const_iterator& )
commit 4f1587965e85e09796c2074d90e9067337f2b710
Author: Noel Grandin <noel at peralex.com>
Date: Wed Jun 17 14:24:53 2015 +0200
tdf#42374 - read PDF in larger chunks
Optimise the reading of the imported PDF file by reading in larger chunks.
Eliminates roughly 10% of the time on my box
Change-Id: I48fff325076850a4ccd32ad85a3092621a923034
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index 4215163..197b39f 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -905,32 +905,6 @@ void Parser::parseLine( const OString& rLine )
SAL_WARN_IF(m_nCharIndex!=-1, "sdext.pdfimport", "leftover scanner input");
}
-oslFileError readLine( oslFileHandle pFile, OStringBuffer& line )
-{
- OSL_PRECOND( line.isEmpty(), "line buf not empty" );
-
- // TODO(P3): read larger chunks
- sal_Char aChar('\n');
- sal_uInt64 nBytesRead;
- oslFileError nRes;
-
- // skip garbage \r \n at start of line
- while( osl_File_E_None == (nRes=osl_readFile(pFile, &aChar, 1, &nBytesRead)) &&
- nBytesRead == 1 &&
- (aChar == '\n' || aChar == '\r') ) ;
-
- if( aChar != '\n' && aChar != '\r' )
- line.append( aChar );
-
- while( osl_File_E_None == (nRes=osl_readFile(pFile, &aChar, 1, &nBytesRead)) &&
- nBytesRead == 1 && aChar != '\n' && aChar != '\r' )
- {
- line.append( aChar );
- }
-
- return nRes;
-}
-
} // namespace
static bool checkEncryption( const OUString& i_rPath,
@@ -1007,6 +981,45 @@ static bool checkEncryption( const OUString& i_rPa
return bSuccess;
}
+class Buffering
+{
+ static const int SIZE = 64*1024;
+ std::unique_ptr<char[]> aBuffer;
+ oslFileHandle& pOut;
+ size_t pos;
+ sal_uInt64 left;
+
+public:
+ Buffering(oslFileHandle& out) : aBuffer(new char[SIZE]), pOut(out), pos(0), left(0) {}
+
+ oslFileError read(char *pChar, short count, sal_uInt64* pBytesRead)
+ {
+ oslFileError nRes = osl_File_E_None;
+ sal_uInt64 nBytesRead = 0;
+ while (count > 0)
+ {
+ if (left == 0)
+ {
+ nRes = osl_readFile(pOut, aBuffer.get(), SIZE, &left);
+ if (nRes != osl_File_E_None || left == 0)
+ {
+ *pBytesRead = nBytesRead;
+ return nRes;
+ }
+ pos = 0;
+ }
+ *pChar = aBuffer.get()[pos];
+ --count;
+ ++pos;
+ --left;
+ ++pChar;
+ ++nBytesRead;
+ }
+ *pBytesRead = nBytesRead;
+ return osl_File_E_None;
+ }
+};
+
bool xpdf_ImportFromFile( const OUString& rURL,
const ContentSinkSharedPtr& rSink,
const uno::Reference< task::XInteractionHandler >& xIHdl,
@@ -1104,9 +1117,36 @@ bool xpdf_ImportFromFile( const OUString& rURL,
// OutputDev. stderr is used for alternate streams, like
// embedded fonts and bitmaps
Parser aParser(rSink,pErr,xContext);
+ Buffering aBuffering(pOut);
OStringBuffer line;
- while( osl_File_E_None == readLine(pOut, line) && !line.isEmpty() )
+ for( ;; )
+ {
+ char aChar('\n');
+ sal_uInt64 nBytesRead;
+ oslFileError nRes;
+
+ // skip garbage \r \n at start of line
+ while( osl_File_E_None == (nRes = aBuffering.read(&aChar, 1, &nBytesRead)) &&
+ nBytesRead == 1 &&
+ (aChar == '\n' || aChar == '\r') ) ;
+ if ( osl_File_E_None != nRes )
+ break;
+
+ if( aChar != '\n' && aChar != '\r' )
+ line.append( aChar );
+
+ while( osl_File_E_None == (nRes = aBuffering.read(&aChar, 1, &nBytesRead)) &&
+ nBytesRead == 1 && aChar != '\n' && aChar != '\r' )
+ {
+ line.append( aChar );
+ }
+ if ( osl_File_E_None != nRes )
+ break;
+ if ( line.isEmpty() )
+ break;
+
aParser.parseLine(line.makeStringAndClear());
+ }
}
}
catch( uno::Exception& )
More information about the Libreoffice-commits
mailing list