mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
Couple of TODO comments to where things appear to be slow.
This commit is contained in:
parent
7b7eccd65e
commit
07ba42176d
@ -266,6 +266,11 @@ func (blk *Block) translate(tx, ty float64) {
|
||||
// drawToPage draws the block on a PdfPage. Generates the content streams and appends to the PdfPage's content
|
||||
// stream and links needed resources.
|
||||
func (blk *Block) drawToPage(page *model.PdfPage) error {
|
||||
|
||||
// TODO(gunnsth): Appears very wasteful to do this all the time.
|
||||
// Possibly create another wrapper around model.PdfPage (creator.page) which can keep track of whether
|
||||
// this has already been done.
|
||||
|
||||
// Check if Page contents are wrapped - if not wrap it.
|
||||
content, err := page.GetAllContentStreams()
|
||||
if err != nil {
|
||||
@ -374,6 +379,10 @@ func (blk *Block) mergeBlocks(toAdd *Block) error {
|
||||
func mergeContents(contents *contentstream.ContentStreamOperations, resources *model.PdfPageResources,
|
||||
contentsToAdd *contentstream.ContentStreamOperations, resourcesToAdd *model.PdfPageResources) error {
|
||||
|
||||
// TODO(gunnsth): It seems rather expensive to mergeContents all the time. A lot of repetition.
|
||||
// It would be more efficient to perform the merge at the very and when we have all the "blocks"
|
||||
// for each page.
|
||||
|
||||
// To properly add contents from a block, we need to handle the resources that the block is
|
||||
// using and make sure it is accessible in the modified Page.
|
||||
//
|
||||
|
35
pdf/creator/paragraph_test.go
Normal file
35
pdf/creator/paragraph_test.go
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.md', which is part of this source code package.
|
||||
*/
|
||||
|
||||
package creator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func benchmarkParagraphAdding(b *testing.B, loops int) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
c := New()
|
||||
for i := 0; i < loops; i++ {
|
||||
p := c.NewParagraph(fmt.Sprintf("Paragraph %d - %d", n, i))
|
||||
err := c.Draw(p)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := c.Write(&buf)
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmark adding multiple paragraphs and writing out.
|
||||
// Check the effects of varying number of paragraphs written out.
|
||||
func BenchmarkParagraphAdding1(b *testing.B) { benchmarkParagraphAdding(b, 1) }
|
||||
func BenchmarkParagraphAdding10(b *testing.B) { benchmarkParagraphAdding(b, 10) }
|
||||
func BenchmarkParagraphAdding100(b *testing.B) { benchmarkParagraphAdding(b, 100) }
|
Loading…
x
Reference in New Issue
Block a user