-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testcase big document #180 #194
Merged
danfickle
merged 20 commits into
danfickle:open-dev-v1
from
rototor:testcase_big_document
Apr 8, 2018
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cf8509a
Created a test for a very big document.
rototor 4a425a0
Whitespace changes
rototor 2769b23
Generate less pages, as this exceeds the memory limits of the
rototor 3df7386
Integrated the sample of @dilworks. Now some bottlenecks become
rototor 26edcbd
Make loggingEnabled in XRLog volatile. This will cause a memory barrier,
rototor 324b36a
Generify LOGGER_NAMES, its just a list of strings...
rototor 97f62a2
Avoid the unneeded boxing which does only a (float) cast internally. The
rototor 6edf6b4
Generify the _childCache
rototor d945ee4
Disable the logging while generating this PDF, as it takes ages anywa…
rototor cdc71cc
Replaced StringBuffer with StringBuilder
rototor 94e0a54
Generfied some stuff, replaced some StringBuffer with StringBuilder, we
rototor 14f4b94
Replace the ancient StringBuffer with StringBuilder, as we never need
rototor 948f57a
We don't need synchronized maps and sets anymore, as we are no longer
rototor eaee674
Generifying stuff all over the place.
rototor a6b50c6
Generifying stuff all over the place.
rototor 003f455
Comment out all this synchronized blocks, as we are not doing any
rototor d0757ef
Future generifing, and replacing of LinkedList with ArrayList
rototor 06eb185
Future removed some LinkedList and replaced them with ArrayList<>()
rototor 2a0b883
Ups, why did this import sneak in?!
rototor 93623a9
Reduce page count and sub rows to get Travis working
danfickle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,21 +60,26 @@ public class CascadedStyle { | |
/** | ||
* Map of PropertyDeclarations, keyed by {@link CSSName} | ||
*/ | ||
private Map cascadedProperties; | ||
private Map<CSSName, PropertyDeclaration> cascadedProperties; | ||
|
||
private String fingerprint; | ||
|
||
/** | ||
* Creates a <code>CascadedStyle</code>, setting the display property to | ||
* to the value of the <code>display</code> parameter. | ||
* Constructs a new CascadedStyle, given an {@link java.util.Iterator} of | ||
* {@link com.openhtmltopdf.css.sheet.PropertyDeclaration}s already sorted | ||
* by specificity of the CSS selector they came from. The Iterator can have | ||
* multiple PropertyDeclarations with the same name; the property cascade | ||
* will be resolved during instantiation, resulting in a set of | ||
* PropertyDeclarations. Once instantiated, properties may be retrieved | ||
* using the normal API for the class. | ||
* | ||
* @param iter An Iterator containing PropertyDeclarations in order of | ||
* specificity. | ||
*/ | ||
public static CascadedStyle createAnonymousStyle(IdentValue display) { | ||
CSSPrimitiveValue val = new PropertyValue(display); | ||
|
||
List props = Collections.singletonList( | ||
new PropertyDeclaration(CSSName.DISPLAY, val, true, StylesheetInfo.USER)); | ||
|
||
return new CascadedStyle(props.iterator()); | ||
CascadedStyle(java.util.Iterator<PropertyDeclaration> iter) { | ||
this(); | ||
|
||
addProperties(iter); | ||
} | ||
|
||
/** | ||
|
@@ -118,60 +123,59 @@ public static PropertyDeclaration createLayoutPropertyDeclaration( | |
return new PropertyDeclaration(cssName, val, true, StylesheetInfo.USER); | ||
} | ||
|
||
private CascadedStyle(CascadedStyle startingPoint, Iterator<PropertyDeclaration> props) { | ||
cascadedProperties = new TreeMap<CSSName, PropertyDeclaration>(startingPoint.cascadedProperties); | ||
|
||
addProperties(props); | ||
} | ||
|
||
/** | ||
* Constructs a new CascadedStyle, given an {@link java.util.Iterator} of | ||
* {@link com.openhtmltopdf.css.sheet.PropertyDeclaration}s already sorted | ||
* by specificity of the CSS selector they came from. The Iterator can have | ||
* multiple PropertyDeclarations with the same name; the property cascade | ||
* will be resolved during instantiation, resulting in a set of | ||
* PropertyDeclarations. Once instantiated, properties may be retrieved | ||
* using the normal API for the class. | ||
* | ||
* @param iter An Iterator containing PropertyDeclarations in order of | ||
* specificity. | ||
* Default constructor with no initialization. Don't use this to instantiate | ||
* the class, as the class is immutable and this will leave it without any | ||
* properties. | ||
*/ | ||
CascadedStyle(java.util.Iterator iter) { | ||
this(); | ||
private CascadedStyle() { | ||
cascadedProperties = new TreeMap<CSSName, PropertyDeclaration>(); | ||
} | ||
/** | ||
* Creates a <code>CascadedStyle</code>, setting the display property to | ||
* to the value of the <code>display</code> parameter. | ||
*/ | ||
public static CascadedStyle createAnonymousStyle(IdentValue display) { | ||
CSSPrimitiveValue val = new PropertyValue(display); | ||
|
||
addProperties(iter); | ||
List<PropertyDeclaration> props = Collections.singletonList( | ||
new PropertyDeclaration(CSSName.DISPLAY, val, true, StylesheetInfo.USER)); | ||
|
||
return new CascadedStyle(props.iterator()); | ||
} | ||
|
||
private void addProperties(java.util.Iterator iter) { | ||
//do a bucket-sort on importance and origin | ||
//properties should already be in order of specificity | ||
java.util.List[] buckets = new java.util.List[PropertyDeclaration.IMPORTANCE_AND_ORIGIN_COUNT]; | ||
for (int i = 0; i < buckets.length; i++) { | ||
buckets[i] = new java.util.LinkedList(); | ||
} | ||
private void addProperties(java.util.Iterator<PropertyDeclaration> iter) { | ||
/* | ||
* do a bucket-sort on importance and origin /properties should already be in | ||
* order of specificity | ||
*/ | ||
//noinspection unchecked | ||
java.util.List<PropertyDeclaration>[] buckets = (java.util.List<PropertyDeclaration>[])new java.util.List[PropertyDeclaration.IMPORTANCE_AND_ORIGIN_COUNT]; | ||
|
||
while (iter.hasNext()) { | ||
PropertyDeclaration prop = (PropertyDeclaration) iter.next(); | ||
buckets[prop.getImportanceAndOrigin()].add(prop); | ||
PropertyDeclaration prop = iter.next(); | ||
List<PropertyDeclaration> bucket = buckets[prop.getImportanceAndOrigin()]; | ||
if (bucket == null) { | ||
bucket = new ArrayList<PropertyDeclaration>(); | ||
buckets[prop.getImportanceAndOrigin()] = bucket; | ||
} | ||
bucket.add(prop); | ||
} | ||
|
||
for (int i = 0; i < buckets.length; i++) { | ||
for (java.util.Iterator it = buckets[i].iterator(); it.hasNext();) { | ||
PropertyDeclaration prop = (PropertyDeclaration) it.next(); | ||
for (List<PropertyDeclaration> bucket : buckets) { | ||
if (bucket == null) | ||
continue; | ||
for (PropertyDeclaration prop : bucket) { | ||
cascadedProperties.put(prop.getCSSName(), prop); | ||
} | ||
} | ||
} | ||
|
||
private CascadedStyle(CascadedStyle startingPoint, Iterator props) { | ||
cascadedProperties = new TreeMap(startingPoint.cascadedProperties); | ||
|
||
addProperties(props); | ||
} | ||
|
||
|
||
/** | ||
* Default constructor with no initialization. Don't use this to instantiate | ||
* the class, as the class is immutable and this will leave it without any | ||
* properties. | ||
*/ | ||
private CascadedStyle() { | ||
cascadedProperties = new TreeMap(); | ||
} | ||
|
||
/** | ||
* Get an empty singleton, used to negate inheritance of properties | ||
|
@@ -186,10 +190,8 @@ private CascadedStyle() { | |
* @return True if the property is defined in this set. | ||
*/ | ||
public boolean hasProperty(CSSName cssName) { | ||
return cascadedProperties.get( cssName ) != null; | ||
return cascadedProperties.get(cssName) != null; | ||
} | ||
|
||
|
||
/** | ||
* Returns a {@link com.openhtmltopdf.css.sheet.PropertyDeclaration} by CSS | ||
* property name, e.g. "font-family". Properties are already cascaded during | ||
|
@@ -201,9 +203,7 @@ public boolean hasProperty(CSSName cssName) { | |
* if not found. | ||
*/ | ||
public PropertyDeclaration propertyByName(CSSName cssName) { | ||
PropertyDeclaration prop = (PropertyDeclaration)cascadedProperties.get(cssName); | ||
|
||
return prop; | ||
return cascadedProperties.get(cssName); | ||
} | ||
|
||
/** | ||
|
@@ -227,23 +227,17 @@ public IdentValue getIdent(CSSName cssName) { | |
* | ||
* @return Iterator over a set of properly cascaded PropertyDeclarations. | ||
*/ | ||
public java.util.Iterator getCascadedPropertyDeclarations() { | ||
List list = new ArrayList(cascadedProperties.size()); | ||
Iterator iter = cascadedProperties.values().iterator(); | ||
while ( iter.hasNext()) { | ||
list.add(iter.next()); | ||
} | ||
return list.iterator(); | ||
public java.util.Collection<PropertyDeclaration> getCascadedPropertyDeclarations() { | ||
return cascadedProperties.values(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This collection here is always directly consumed and iterated over. There was no sense in copying this... |
||
} | ||
|
||
public int countAssigned() { return cascadedProperties.size(); } | ||
|
||
public String getFingerprint() { | ||
if (this.fingerprint == null) { | ||
StringBuffer sb = new StringBuffer(); | ||
Iterator iter = cascadedProperties.values().iterator(); | ||
while (iter.hasNext()) { | ||
sb.append(((PropertyDeclaration)iter.next()).getFingerprint()); | ||
StringBuilder sb = new StringBuilder(); | ||
for (PropertyDeclaration o : cascadedProperties.values()) { | ||
sb.append(o.getFingerprint()); | ||
} | ||
this.fingerprint = sb.toString(); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something IDEA cached ... if refs == null, the addAll would throw an NPE...