Simplify some WriteBlockAtOffset() calls. These IFX_SeekableStream::WriteBlockAtOffset() calls can be simplified to just calling WriteBlock(), since they only happen when: - A stream has just been created, and the offset is 0. - When the offset is the end, which is what WriteBlock() does. In turn, WriteBlock() simplifies to WriteString() in most places. Change-Id: Ifa66932dc9a75787bafba5832e6c100a0a3342bd Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60890 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 662af58..1e4c836 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -442,9 +442,7 @@ RetainPtr<IFX_SeekableStream> fileWrite = MakeSeekableStream(pFileHandler); if (fileType == FXFA_SAVEAS_XML) { - ByteString content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; - fileWrite->WriteBlockAtOffset(content.c_str(), fileWrite->GetSize(), - content.GetLength()); + fileWrite->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); CXFA_FFDoc* ffdoc = m_pContext->GetXFADocView()->GetDoc(); ffdoc->SavePackage( ToNode(ffdoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Data)), fileWrite); @@ -497,13 +495,11 @@ static const char kFormat[] = "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; ByteString content = ByteString::Format(kFormat, bPath.c_str()); - fileWrite->WriteBlockAtOffset(content.c_str(), fileWrite->GetSize(), - content.GetLength()); + fileWrite->WriteString(content.AsStringView()); } auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream); pAcc->LoadAllDataFiltered(); - fileWrite->WriteBlockAtOffset(pAcc->GetData(), fileWrite->GetSize(), - pAcc->GetSize()); + fileWrite->WriteBlock(pAcc->GetData(), pAcc->GetSize()); } } fileWrite->Flush(); @@ -713,10 +709,7 @@ CXFA_FFDoc* ffdoc = m_pContext->GetXFADocView()->GetDoc(); RetainPtr<IFX_SeekableStream> fileStream = MakeSeekableStream(pFileHandler); if (fileType == FXFA_SAVEAS_XML) { - static constexpr char kContent[] = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; - fileStream->WriteBlockAtOffset(kContent, 0, strlen(kContent)); - + fileStream->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"); ffdoc->SavePackage( ToNode(ffdoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Data)), fileStream);