diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-01-25 14:08:19 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-01-26 09:54:30 +0100 |
commit | 90948976a557c49ec5e971b8ba6d8e62c58b6c7e (patch) | |
tree | 9f06cdeccd3c57051fec79e6171d535099440dff /hwpfilter | |
parent | 853e3fb639a540b2a452ee7116ae61e7b581f8fd (diff) |
drop the slow path
Change-Id: Ibf9721d852c1b57593e34272214d9f11c0188016
Reviewed-on: https://gerrit.libreoffice.org/48611
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'hwpfilter')
-rw-r--r-- | hwpfilter/source/hinfo.cxx | 61 | ||||
-rw-r--r-- | hwpfilter/source/hiodev.cxx | 18 | ||||
-rw-r--r-- | hwpfilter/source/hiodev.h | 3 | ||||
-rw-r--r-- | hwpfilter/source/hpara.cxx | 10 | ||||
-rw-r--r-- | hwpfilter/source/htags.cxx | 13 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.cxx | 12 | ||||
-rw-r--r-- | hwpfilter/source/hwpfile.h | 5 | ||||
-rw-r--r-- | hwpfilter/source/hwpread.cxx | 76 |
8 files changed, 88 insertions, 110 deletions
diff --git a/hwpfilter/source/hinfo.cxx b/hwpfilter/source/hinfo.cxx index d6b30ee6b815..9cf5907e9950 100644 --- a/hwpfilter/source/hinfo.cxx +++ b/hwpfilter/source/hinfo.cxx @@ -78,8 +78,8 @@ void HWPInfo::Read(HWPFile & hwpf) hwpf.Read2b(&cur_col, 1); /* When a document is saving, the paragraph number where the coursor is */ hwpf.Read2b(&cur_row, 1); /* Paragraphs rows */ - hwpf.Read1b(&paper.paper_kind, 1); /* Paper Type */ - hwpf.Read1b(&paper.paper_direction, 1); /* Paper orientation */ + hwpf.Read1b(paper.paper_kind); /* Paper Type */ + hwpf.Read1b(paper.paper_direction); /* Paper orientation */ // paper geometry information unsigned short tmp16; @@ -111,15 +111,14 @@ void HWPInfo::Read(HWPFile & hwpf) return; paper.gutter_length = tmp16; /* The binding margin */ hwpf.Read2b(&readonly, 1); /* Reserve */ - hwpf.Read1b(reserved1, 4); /* Reserve */ - hwpf.Read1b(&chain_info.chain_page_no, 1); /* Connect page number: 1-Connect, 0-newly started (used in connection printing) */ - hwpf.Read1b(&chain_info.chain_footnote_no, 1);/* Connect footnote number: 1-connect, 0-newly started*/ + hwpf.ReadBlock(reserved1, 4); /* Reserve */ + hwpf.Read1b(chain_info.chain_page_no); /* Connect page number: 1-Connect, 0-newly started (used in connection printing) */ + hwpf.Read1b(chain_info.chain_footnote_no); /* Connect footnote number: 1-connect, 0-newly started*/ /* the file name to be printed with connection */ - hwpf.Read1b(chain_info.chain_filename, CHAIN_MAX_PATH); + hwpf.ReadBlock(chain_info.chain_filename, CHAIN_MAX_PATH); - hwpf.Read1b(annotation, ANNOTATION_LEN); /* Annotation (additional information when a file is saving.) */ + hwpf.ReadBlock(annotation, ANNOTATION_LEN); /* Annotation (additional information when a file is saving.) */ hwpf.Read2b(&encrypted, 1); /* encrypt: 0-normal file(without password), 1-protected by password */ -//hwpf.Read1b(reserved2, 6); /* it turned into below three values. */ hwpf.Read2b(&beginpagenum,1); /* Page starting number */ // footnote @@ -135,8 +134,8 @@ void HWPInfo::Read(HWPFile & hwpf) if (!hwpf.Read2b(tmp16)) return; spfnfn = tmp16; - hwpf.Read1b(&fnchar, 1); - hwpf.Read1b(&fnlinetype, 1); + hwpf.Read1b(fnchar); + hwpf.Read1b(fnlinetype); // border layout for (int & ii : bordermargin) { @@ -146,11 +145,11 @@ void HWPInfo::Read(HWPFile & hwpf) } hwpf.Read2b(&borderline, 1); - hwpf.Read1b(&empty_line_hide, 1); - hwpf.Read1b(&table_move, 1); - hwpf.Read1b(&compressed, 1); + hwpf.Read1b(empty_line_hide); + hwpf.Read1b(table_move); + hwpf.Read1b(compressed); - hwpf.Read1b(&reserved3, 1); + hwpf.Read1b(reserved3); hwpf.Read2b(&info_block_len, 1); if (hwpf.State()) @@ -231,18 +230,18 @@ void ParaShape::Read(HWPFile & hwpf) return; pspacing_next = tmp16; - hwpf.Read1b(&condense, 1); - hwpf.Read1b(&arrange_type, 1); + hwpf.Read1b(condense); + hwpf.Read1b(arrange_type); for (TabSet & tab : tabs) { - hwpf.Read1b(&tab.type, 1); - hwpf.Read1b(&tab.dot_continue, 1); + hwpf.Read1b(tab.type); + hwpf.Read1b(tab.dot_continue); if (!hwpf.Read2b(tmp16)) return; tab.position = tmp16; } - hwpf.Read1b(&coldef.ncols, 1); - hwpf.Read1b(&coldef.separator, 1); + hwpf.Read1b(coldef.ncols); + hwpf.Read1b(coldef.separator); if (!hwpf.Read2b(tmp16)) return; coldef.spacing = tmp16; @@ -252,14 +251,14 @@ void ParaShape::Read(HWPFile & hwpf) if (!hwpf.Read2b(tmp16)) return; coldef.columnlen0 = tmp16; - hwpf.Read1b(&shade, 1); - hwpf.Read1b(&outline, 1); - hwpf.Read1b(&outline_continue, 1); + hwpf.Read1b(shade); + hwpf.Read1b(outline); + hwpf.Read1b(outline_continue); if (!hwpf.Read2b(tmp16)) return; pspacing_prev = tmp16; - hwpf.Read1b(reserved, 2); + hwpf.ReadBlock(reserved, 2); } @@ -269,13 +268,13 @@ void CharShape::Read(HWPFile & hwpf) if (!hwpf.Read2b(tmp16)) return; size = tmp16; - hwpf.Read1b(font, NLanguage); - hwpf.Read1b(ratio, NLanguage); - hwpf.Read1b(space, NLanguage); - hwpf.Read1b(color, 2); - hwpf.Read1b(&shade, 1); - hwpf.Read1b(&attr, 1); - hwpf.Read1b(reserved, 4); + hwpf.ReadBlock(font, NLanguage); + hwpf.ReadBlock(ratio, NLanguage); + hwpf.ReadBlock(space, NLanguage); + hwpf.ReadBlock(color, 2); + hwpf.Read1b(shade); + hwpf.Read1b(attr); + hwpf.ReadBlock(reserved, 4); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hiodev.cxx b/hwpfilter/source/hiodev.cxx index 22299e4344cd..bed8b37ce783 100644 --- a/hwpfilter/source/hiodev.cxx +++ b/hwpfilter/source/hiodev.cxx @@ -53,24 +53,6 @@ void HIODev::init() compressed = false; } - -size_t HIODev::read1b(void *ptr, size_t nmemb) -{ - uchar *p = static_cast<uchar *>(ptr); - - if (state()) - return 0; - size_t ii; - for (ii = 0; ii < nmemb; ++ii) - { - if (!read1b(p[ii])) - break; - if (state()) - break; - } - return ii; -} - size_t HIODev::read2b(void *ptr, size_t nmemb) { ushort *p = static_cast<ushort *>(ptr); diff --git a/hwpfilter/source/hiodev.h b/hwpfilter/source/hiodev.h index af49703c3482..3e307153fdc5 100644 --- a/hwpfilter/source/hiodev.h +++ b/hwpfilter/source/hiodev.h @@ -59,7 +59,6 @@ class DLLEXPORT HIODev virtual size_t readBlock( void *ptr, size_t size ) = 0; virtual size_t skipBlock( size_t size ) = 0; - size_t read1b( void *ptr, size_t nmemb ); size_t read2b( void *ptr, size_t nmemb ); size_t read4b( void *ptr, size_t nmemb ); }; @@ -100,7 +99,6 @@ class HStreamIODev final: public HIODev /** * Read one byte from stream */ - using HIODev::read1b; virtual bool read1b(unsigned char &out) override; virtual bool read1b(char &out) override; /** @@ -147,7 +145,6 @@ class HMemIODev final: public HIODev virtual int state() const override; /* gzip routine wrapper */ virtual bool setCompressed( bool ) override; - using HIODev::read1b; virtual bool read1b(unsigned char &out) override; virtual bool read1b(char &out) override; using HIODev::read2b; diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx index 79fd93145ad8..deda63421b60 100644 --- a/hwpfilter/source/hpara.cxx +++ b/hwpfilter/source/hpara.cxx @@ -93,13 +93,13 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag) int ii; scflag = flag; // Paragraph Information - hwpf.Read1b(&reuse_shape, 1); + hwpf.Read1b(reuse_shape); hwpf.Read2b(&nch, 1); hwpf.Read2b(&nline, 1); - hwpf.Read1b(&contain_cshape, 1); - hwpf.Read1b(&etcflag, 1); + hwpf.Read1b(contain_cshape); + hwpf.Read1b(etcflag); hwpf.Read4b(&ctrlflag, 1); - hwpf.Read1b(&pstyno, 1); + hwpf.Read1b(pstyno); /* Paragraph representative character */ cshape->Read(hwpf); @@ -148,7 +148,7 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag) memset(cshapep[ii].get(), 0, sizeof(CharShape)); unsigned char same_cshape(0); - hwpf.Read1b(&same_cshape, 1); + hwpf.Read1b(same_cshape); if (!same_cshape) { cshapep[ii]->Read(hwpf); diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx index f9952e009f8b..0c011731c1d4 100644 --- a/hwpfilter/source/htags.cxx +++ b/hwpfilter/source/htags.cxx @@ -27,11 +27,12 @@ bool HyperText::Read(HWPFile& hwpf) { - size_t nRead = hwpf.Read1b(filename, 256); + size_t nRead = hwpf.ReadBlock(filename, 256); nRead += hwpf.Read2b(bookmark, 16); - nRead += hwpf.Read1b(macro, 325); - nRead += hwpf.Read1b(&type, 1); - nRead += hwpf.Read1b(reserve, 3); + nRead += hwpf.ReadBlock(macro, 325); + if (hwpf.Read1b(type)) + ++nRead; + nRead += hwpf.ReadBlock(reserve, 3); if( type == 2 ) { for( int i = 1; i < 256; i++) @@ -61,8 +62,8 @@ bool EmPicture::Read(HWPFile & hwpf) { if (size == 0) return false; - hwpf.Read1b(name, 16); - hwpf.Read1b(type, 16); + hwpf.ReadBlock(name, 16); + hwpf.ReadBlock(type, 16); name[0] = 'H'; name[1] = 'W'; name[2] = 'P'; diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx index f10334707130..f7b78fdf704c 100644 --- a/hwpfilter/source/hwpfile.cxx +++ b/hwpfilter/source/hwpfile.cxx @@ -122,6 +122,13 @@ int HWPFile::SetState(int errcode) return error_code; } +bool HWPFile::Read1b(unsigned char &out) +{ + if (!hiodev || !hiodev->read1b(out)) + return false; + return true; +} + bool HWPFile::Read1b(char &out) { unsigned char tmp8; @@ -150,11 +157,6 @@ bool HWPFile::Read4b(int &out) return true; } -size_t HWPFile::Read1b(void *ptr, size_t nmemb) -{ - return hiodev ? hiodev->read1b(ptr, nmemb) : 0; -} - size_t HWPFile::Read2b(void *ptr, size_t nmemb) { return hiodev ? hiodev->read2b(ptr, nmemb) : 0; diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h index 645219216ab5..e4f27e44c187 100644 --- a/hwpfilter/source/hwpfile.h +++ b/hwpfilter/source/hwpfile.h @@ -127,6 +127,7 @@ class DLLEXPORT HWPFile /** * Reads one byte from HIODev */ + bool Read1b(unsigned char &out); bool Read1b(char &out); /** * Reads two byte from HIODev @@ -138,10 +139,6 @@ class DLLEXPORT HWPFile bool Read4b(unsigned int &out); bool Read4b(int &out); /** - * Reads nmemb byte array from HIODev - */ - size_t Read1b(void *ptr, size_t nmemb); -/** * Reads nmemb short type array from HIODev */ size_t Read2b(void *ptr, size_t nmemb); diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx index bb8df6defe4a..1ed8001513af 100644 --- a/hwpfilter/source/hwpread.cxx +++ b/hwpfilter/source/hwpread.cxx @@ -71,10 +71,10 @@ bool FieldCode::Read(HWPFile & hwpf) hwpf.Read4b(&size, 1); hwpf.Read2b(&dummy, 1); - hwpf.Read1b(&type, 2); + hwpf.ReadBlock(&type, 2); hwpf.Read4b(reserved1.data(), 1); hwpf.Read2b(&location_info, 1); - hwpf.Read1b(reserved2.data(), 22); + hwpf.ReadBlock(reserved2.data(), 22); hwpf.Read4b(&len1, 1); hwpf.Read4b(&len2, 1); hwpf.Read4b(&len3, 1); @@ -197,14 +197,14 @@ bool Cell::Read(HWPFile & hwpf) hwpf.Read2b(&txthigh, 1); hwpf.Read2b(&cellhigh, 1); - hwpf.Read1b(&flag, 1); - hwpf.Read1b(&changed, 1); - hwpf.Read1b(&used, 1); - hwpf.Read1b(&ver_align, 1); - hwpf.Read1b(linetype, 4); - hwpf.Read1b(&shade, 1); - hwpf.Read1b(&diagonal, 1); - return hwpf.Read1b(&protect, 1) == 1; + hwpf.Read1b(flag); + hwpf.Read1b(changed); + hwpf.Read1b(used); + hwpf.Read1b(ver_align); + hwpf.ReadBlock(linetype, 4); + hwpf.Read1b(shade); + hwpf.Read1b(diagonal); + return hwpf.Read1b(protect); } bool TxtBox::Read(HWPFile & hwpf) @@ -226,8 +226,8 @@ bool TxtBox::Read(HWPFile & hwpf) style.boxnum = fboxnum++; zorder = zindex++; - hwpf.Read1b(&style.anchor_type, 1); - hwpf.Read1b(&style.txtflow, 1); + hwpf.Read1b(style.anchor_type); + hwpf.Read1b(style.txtflow); hwpf.Read2b(&style.xpos, 1); hwpf.Read2b(&style.ypos, 1); hwpf.Read2b(&option, 1); @@ -242,10 +242,10 @@ bool TxtBox::Read(HWPFile & hwpf) hwpf.Read2b(&xs, 1); hwpf.Read2b(&ys, 1); hwpf.Read2b(&cap_margin, 1); - hwpf.Read1b(&xpos_type, 1); - hwpf.Read1b(&ypos_type, 1); - hwpf.Read1b(&smart_linesp, 1); - hwpf.Read1b(&reserved1, 1); + hwpf.Read1b(xpos_type); + hwpf.Read1b(ypos_type); + hwpf.Read1b(smart_linesp); + hwpf.Read1b(reserved1); hwpf.Read2b(&pgx, 1); hwpf.Read2b(&pgy, 1); hwpf.Read2b(&pgno, 1); @@ -381,8 +381,8 @@ bool Picture::Read(HWPFile & hwpf) style.boxnum = fboxnum++; zorder = zindex++; - hwpf.Read1b(&style.anchor_type, 1); /* Reference position */ - hwpf.Read1b(&style.txtflow, 1); /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */ + hwpf.Read1b(style.anchor_type); /* Reference position */ + hwpf.Read1b(style.txtflow); /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */ hwpf.Read2b(&style.xpos, 1); /* Horizontal position: 1=left, 2=right, 3=center, and others=any */ hwpf.Read2b(&style.ypos, 1); /* Vertical position: 1=top, 2=down, 3=middle, and others=any */ hwpf.Read2b(&option, 1); /* Other options: Borders, reverse picture, and so on. Save as bit. */ @@ -396,10 +396,10 @@ bool Picture::Read(HWPFile & hwpf) hwpf.Read2b(&xs, 1); /* The total size (box size + caption + margin) Horizontal */ hwpf.Read2b(&ys, 1); /* Vertical */ hwpf.Read2b(&cap_margin, 1); /* Caption margins */ - hwpf.Read1b(&xpos_type, 1); - hwpf.Read1b(&ypos_type, 1); - hwpf.Read1b(&smart_linesp, 1); /* Line Spacing protection: 0 unprotected 1 protected */ - hwpf.Read1b(&reserved1, 1); + hwpf.Read1b(xpos_type); + hwpf.Read1b(ypos_type); + hwpf.Read1b(smart_linesp); /* Line Spacing protection: 0 unprotected 1 protected */ + hwpf.Read1b(reserved1); hwpf.Read2b(&pgx, 1); /* Real Calculated box width */ hwpf.Read2b(&pgy, 1); /* Height */ hwpf.Read2b(&pgno, 1); /* Page number: starts from 0 */ @@ -407,7 +407,7 @@ bool Picture::Read(HWPFile & hwpf) hwpf.Read2b(&cap_pos, 1); /* Caption positions 0-7 Menu Order. */ hwpf.Read2b(&num, 1); /* Box number, serial number which starts from 0 */ - hwpf.Read1b(&pictype, 1); /* Picture type */ + hwpf.Read1b(pictype); /* Picture type */ unsigned short tmp16; if (!hwpf.Read2b(tmp16)) /* the real horizontal starting point where shows the picture */ @@ -423,8 +423,8 @@ bool Picture::Read(HWPFile & hwpf) return false; scale[1] = tmp16; - hwpf.Read1b(picinfo.picun.path, 256); /* Picture File Name: when type is not a Drawing. */ - hwpf.Read1b(reserved3, 9); /* Brightness / Contrast / Picture Effect, etc. */ + hwpf.ReadBlock(picinfo.picun.path, 256); /* Picture File Name: when type is not a Drawing. */ + hwpf.ReadBlock(reserved3, 9); /* Brightness / Contrast / Picture Effect, etc. */ UpdateBBox(this); if( pictype != PICTYPE_DRAW ) @@ -517,9 +517,9 @@ bool Line::Read(HWPFile & hwpf) style.boxnum = fboxnum++; zorder = zindex++; style.boxtype = 'L'; - hwpf.Read1b(&reserved2, 8); - hwpf.Read1b(&style.anchor_type, 1); - hwpf.Read1b(&style.txtflow, 1); + hwpf.ReadBlock(&reserved2, 8); + hwpf.Read1b(style.anchor_type); + hwpf.Read1b(style.txtflow); hwpf.Read2b(&style.xpos, 1); hwpf.Read2b(&style.ypos, 1); hwpf.Read2b(&option, 1); @@ -537,8 +537,8 @@ bool Line::Read(HWPFile & hwpf) hwpf.linenumber = 1; hwpf.Read2b(&boundsy, 1); hwpf.Read2b(&boundey, 1); - hwpf.Read1b(&boundx, 1); - hwpf.Read1b(&draw, 1); + hwpf.Read1b(boundx); + hwpf.Read1b(draw); hwpf.Read2b(&pgx, 1); hwpf.Read2b(&pgy, 1); @@ -572,7 +572,7 @@ bool Hidden::Read(HWPFile & hwpf) return hwpf.SetState(HWP_InvalidFileFormat); } - hwpf.Read1b(info, 8); + hwpf.ReadBlock(info, 8); hwpf.ReadParaList(plist); return !hwpf.State(); @@ -597,9 +597,9 @@ bool HeaderFooter::Read(HWPFile & hwpf) return hwpf.SetState(HWP_InvalidFileFormat); } - hwpf.Read1b(info, 8); - hwpf.Read1b(&type, 1); - hwpf.Read1b(&where, 1); + hwpf.ReadBlock(info, 8); + hwpf.Read1b(type); + hwpf.Read1b(where); lnnumber = 0; hwpf.ReadParaList(plist, CH_HEADER_FOOTER); linenumber = sal::static_int_cast<unsigned char>(lnnumber); @@ -629,7 +629,7 @@ bool Footnote::Read(HWPFile & hwpf) return hwpf.SetState(HWP_InvalidFileFormat); } - hwpf.Read1b(info, 8); + hwpf.ReadBlock(info, 8); hwpf.Read2b(&number, 1); hwpf.Read2b(&type, 1); unsigned short tmp16; @@ -741,7 +741,7 @@ MailMerge::MailMerge() bool MailMerge::Read(HWPFile & hwpf) { - hwpf.Read1b(field_name, 20); + hwpf.ReadBlock(field_name, 20); hwpf.Read2b(&dummy, 1); if (hh != dummy){ @@ -844,8 +844,8 @@ Outline::Outline() bool Outline::Read(HWPFile & hwpf) { hwpf.Read2b(&kind, 1); - hwpf.Read1b(&shape, 1); - hwpf.Read1b(&level, 1); + hwpf.Read1b(shape); + hwpf.Read1b(level); hwpf.Read2b(number, 7); hwpf.Read2b(user_shape, 7); hwpf.Read2b(deco, 14); |