Skip to content

Commit

Permalink
Megamorphic methods, move outta here!
Browse files Browse the repository at this point in the history
This is part of a potentially-large effort to reduce the number of implementations of common interfaces, like Collection and Set, that might be passed at any of an individual program's frequent callsites. Arrays.asList() and Collections.emptySet() are serious offenders here, each defining its own class it returns but that is used nowhere else. If you expect an ArrayList, then use Maker.makeList(), which now has an optimization for the one-argument case. If you expect an OrderedSet, there's Maker.makeOS(), but if you expect it to be empty, just use new OrderedSet<>() rather than Collections.emptySet(). Similarly, there's Maker.makeUOS() for UnorderedSet instances. If you want to know the effect this can have, see this Guava issue google/guava#1268 ; a 20x slowdown can happen at megamorphic callsites. There's an explanation of the terms I used here http://insightfullogic.com/2014/May/12/fast-and-megamorphic-what-influences-method-invoca/ .
  • Loading branch information
tommyettinger committed Mar 5, 2019
1 parent 37e0f27 commit 8ac91c8
Show file tree
Hide file tree
Showing 98 changed files with 7,670 additions and 14,073 deletions.
1 change: 0 additions & 1 deletion docs/squidlib-util/apidocs/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="squidpony/squidmath/CrossHash.Jolt.html" title="class in squidpony.squidmath" target="classFrame">CrossHash.Jolt</a></li>
<li><a href="squidpony/squidmath/CrossHash.Lightning.html" title="class in squidpony.squidmath" target="classFrame">CrossHash.Lightning</a></li>
<li><a href="squidpony/squidmath/CrossHash.Mist.html" title="class in squidpony.squidmath" target="classFrame">CrossHash.Mist</a></li>
<li><a href="squidpony/squidmath/CrossHash.Squish.html" title="class in squidpony.squidmath" target="classFrame">CrossHash.Squish</a></li>
<li><a href="squidpony/squidmath/CrossHash.Wisp.html" title="class in squidpony.squidmath" target="classFrame">CrossHash.Wisp</a></li>
<li><a href="squidpony/squidai/CustomDijkstraMap.html" title="class in squidpony.squidai" target="classFrame">CustomDijkstraMap</a></li>
<li><a href="squidpony/DamerauLevenshteinAlgorithm.html" title="class in squidpony" target="classFrame">DamerauLevenshteinAlgorithm</a></li>
Expand Down
1 change: 0 additions & 1 deletion docs/squidlib-util/apidocs/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ <h1 class="bar">All&nbsp;Classes</h1>
<li><a href="squidpony/squidmath/CrossHash.Jolt.html" title="class in squidpony.squidmath">CrossHash.Jolt</a></li>
<li><a href="squidpony/squidmath/CrossHash.Lightning.html" title="class in squidpony.squidmath">CrossHash.Lightning</a></li>
<li><a href="squidpony/squidmath/CrossHash.Mist.html" title="class in squidpony.squidmath">CrossHash.Mist</a></li>
<li><a href="squidpony/squidmath/CrossHash.Squish.html" title="class in squidpony.squidmath">CrossHash.Squish</a></li>
<li><a href="squidpony/squidmath/CrossHash.Wisp.html" title="class in squidpony.squidmath">CrossHash.Wisp</a></li>
<li><a href="squidpony/squidai/CustomDijkstraMap.html" title="class in squidpony.squidai">CustomDijkstraMap</a></li>
<li><a href="squidpony/DamerauLevenshteinAlgorithm.html" title="class in squidpony">DamerauLevenshteinAlgorithm</a></li>
Expand Down
15 changes: 15 additions & 0 deletions docs/squidlib-util/apidocs/index-files/index-14.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ <h2 class="title">M</h2>
<dd>
<div class="block">Makes an ArrayList of T given an array or vararg of T elements.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/Maker.html#makeList-T-">makeList(T)</a></span> - Static method in class squidpony.<a href="../squidpony/Maker.html" title="class in squidpony">Maker</a></dt>
<dd>
<div class="block">Makes an ArrayList of T given a single T element; avoids creating an array for varargs as
<a href="../squidpony/Maker.html#makeList-T...-"><code>Maker.makeList(Object[])</code></a> would do, but only allows one item.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/IntIntOrderedMap.html#makeMap-int-int-int...-">makeMap(int, int, int...)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/IntIntOrderedMap.html" title="class in squidpony.squidmath">IntIntOrderedMap</a></dt>
<dd>
<div class="block">Makes an IntIntOrderedMap using the given int keys and values in alternating key-value-key-value order.</div>
Expand Down Expand Up @@ -242,6 +247,11 @@ <h2 class="title">M</h2>
<dd>
<div class="block">Makes an OrderedSet (OS) of T given an array or vararg of T elements.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/Maker.html#makeOS-T-">makeOS(T)</a></span> - Static method in class squidpony.<a href="../squidpony/Maker.html" title="class in squidpony">Maker</a></dt>
<dd>
<div class="block">Makes an OrderedSet of T given a single T element; avoids creating an array for varargs as
<a href="../squidpony/Maker.html#makeOS-T...-"><code>Maker.makeOS(Object[])</code></a> would do, but only allows one item.</div>
</dd>
<dt><a href="../squidpony/Maker.html" title="class in squidpony"><span class="typeNameLink">Maker</span></a> - Class in <a href="../squidpony/package-summary.html">squidpony</a></dt>
<dd>
<div class="block">Utility methods for more easily constructing data structures, particularly those in Java's standard library.</div>
Expand All @@ -254,6 +264,11 @@ <h2 class="title">M</h2>
<dd>
<div class="block">Makes an UnorderedSet (UOS) of T given an array or vararg of T elements.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/Maker.html#makeUOS-T-">makeUOS(T)</a></span> - Static method in class squidpony.<a href="../squidpony/Maker.html" title="class in squidpony">Maker</a></dt>
<dd>
<div class="block">Makes an UnorderedSet of T given a single T element; avoids creating an array for varargs as
<a href="../squidpony/Maker.html#makeOS-T...-"><code>Maker.makeOS(Object[])</code></a> would do, but only allows one item.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidgrid/mapping/MetsaMapFactory.html#makeWeightedMap--">makeWeightedMap()</a></span> - Method in class squidpony.squidgrid.mapping.<a href="../squidpony/squidgrid/mapping/MetsaMapFactory.html" title="class in squidpony.squidgrid.mapping">MetsaMapFactory</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/FastNoise.html#MANHATTAN">MANHATTAN</a></span> - Static variable in class squidpony.squidmath.<a href="../squidpony/squidmath/FastNoise.html" title="class in squidpony.squidmath">FastNoise</a></dt>
Expand Down
20 changes: 20 additions & 0 deletions docs/squidlib-util/apidocs/index-files/index-19.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ <h2 class="title">R</h2>
<dd>
<div class="block">Makes a new Mist with all of the salt values altered based on the previous salt values.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/DiverRNG.html#randomize-long-">randomize(long)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/DiverRNG.html" title="class in squidpony.squidmath">DiverRNG</a></dt>
<dd>
<div class="block">High-quality static randomizing method that takes its state as a parameter; state is expected to change between
calls to this.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/JabRNG.html#randomize-long-">randomize(long)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/JabRNG.html" title="class in squidpony.squidmath">JabRNG</a></dt>
<dd>
<div class="block">Call with <code>nextLong(z += 0x3C6EF372FE94F82AL)</code>.</div>
Expand All @@ -355,6 +360,21 @@ <h2 class="title">R</h2>
<dd>
<div class="block">Randomly add appearance descriptors to a copy of the Chimera creature.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/DiverRNG.html#randomizeBounded-long-int-">randomizeBounded(long, int)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/DiverRNG.html" title="class in squidpony.squidmath">DiverRNG</a></dt>
<dd>
<div class="block">High-quality static randomizing method that takes its state as a parameter and limits output to an int between 0
(inclusive) and bound (exclusive); state is expected to change between calls to this.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/DiverRNG.html#randomizeDouble-long-">randomizeDouble(long)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/DiverRNG.html" title="class in squidpony.squidmath">DiverRNG</a></dt>
<dd>
<div class="block">Returns a random double that is deterministic based on state; if state is the same on two calls to this, this
will return the same float.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/DiverRNG.html#randomizeFloat-long-">randomizeFloat(long)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/DiverRNG.html" title="class in squidpony.squidmath">DiverRNG</a></dt>
<dd>
<div class="block">Returns a random float that is deterministic based on state; if state is the same on two calls to this, this will
return the same float.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/MonsterGen.html#randomizePowers-squidpony.squidmath.RNG-squidpony.MonsterGen.Chimera-java.lang.String-int-">randomizePowers(RNG, MonsterGen.Chimera, String, int)</a></span> - Method in class squidpony.<a href="../squidpony/MonsterGen.html" title="class in squidpony">MonsterGen</a></dt>
<dd>
<div class="block">Randomly add power descriptors to a copy of the Chimera creature.</div>
Expand Down
2 changes: 0 additions & 2 deletions docs/squidlib-util/apidocs/index-files/index-20.html
Original file line number Diff line number Diff line change
Expand Up @@ -2669,8 +2669,6 @@ <h2 class="title">S</h2>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/SquidTags.html#SquidTags--">SquidTags()</a></span> - Constructor for class squidpony.<a href="../squidpony/SquidTags.html" title="class in squidpony">SquidTags</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/CrossHash.Squish.html#Squish--">Squish()</a></span> - Constructor for class squidpony.squidmath.<a href="../squidpony/squidmath/CrossHash.Squish.html" title="class in squidpony.squidmath">CrossHash.Squish</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="../squidpony/FakeLanguageGen.html#srng">srng</a></span> - Static variable in class squidpony.<a href="../squidpony/FakeLanguageGen.html" title="class in squidpony">FakeLanguageGen</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="../squidpony/MonsterGen.html#srng">srng</a></span> - Static variable in class squidpony.<a href="../squidpony/MonsterGen.html" title="class in squidpony">MonsterGen</a></dt>
Expand Down
2 changes: 0 additions & 2 deletions docs/squidlib-util/apidocs/index-files/index-4.html
Original file line number Diff line number Diff line change
Expand Up @@ -1965,8 +1965,6 @@ <h2 class="title">C</h2>
<div class="block">A whole cluster of Wisp-like hash functions that sacrifice a small degree of speed, but can be built with up
to 128 bits of salt values that help to obscure what hashing function is actually being used.</div>
</dd>
<dt><a href="../squidpony/squidmath/CrossHash.Squish.html" title="class in squidpony.squidmath"><span class="typeNameLink">CrossHash.Squish</span></a> - Class in <a href="../squidpony/squidmath/package-summary.html">squidpony.squidmath</a></dt>
<dd>&nbsp;</dd>
<dt><a href="../squidpony/squidmath/CrossHash.Wisp.html" title="class in squidpony.squidmath"><span class="typeNameLink">CrossHash.Wisp</span></a> - Class in <a href="../squidpony/squidmath/package-summary.html">squidpony.squidmath</a></dt>
<dd>
<div class="block">The fastest hash in CrossHash, with middling quality.</div>
Expand Down
7 changes: 4 additions & 3 deletions docs/squidlib-util/apidocs/index-files/index-5.html
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ <h2 class="title">D</h2>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/DiverRNG.html#determine-long-">determine(long)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/DiverRNG.html" title="class in squidpony.squidmath">DiverRNG</a></dt>
<dd>
<div class="block">Static randomizing method that takes its state as a parameter; state is expected to change between calls to this.</div>
<div class="block">Fast static randomizing method that takes its state as a parameter; state is expected to change between calls to
this.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/FlapRNG.html#determine-int-">determine(int)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/FlapRNG.html" title="class in squidpony.squidmath">FlapRNG</a></dt>
<dd>
Expand Down Expand Up @@ -622,8 +623,8 @@ <h2 class="title">D</h2>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/DiverRNG.html#determineBounded-long-int-">determineBounded(long, int)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/DiverRNG.html" title="class in squidpony.squidmath">DiverRNG</a></dt>
<dd>
<div class="block">Static randomizing method that takes its state as a parameter and limits output to an int between 0 (inclusive)
and bound (exclusive); state is expected to change between calls to this.</div>
<div class="block">Fast static randomizing method that takes its state as a parameter and limits output to an int between 0
(inclusive) and bound (exclusive); state is expected to change between calls to this.</div>
</dd>
<dt><span class="memberNameLink"><a href="../squidpony/squidmath/FlapRNG.html#determineBounded-int-int-">determineBounded(int, int)</a></span> - Static method in class squidpony.squidmath.<a href="../squidpony/squidmath/FlapRNG.html" title="class in squidpony.squidmath">FlapRNG</a></dt>
<dd>
Expand Down

0 comments on commit 8ac91c8

Please sign in to comment.