Skip to content

Commit

Permalink
performance tuning using more final modifiers in the kelondro core
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6402 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Oct 12, 2009
1 parent cb4de9c commit 2a7fe35
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 189 deletions.
10 changes: 5 additions & 5 deletions source/net/yacy/kelondro/index/BinSearch.java
Expand Up @@ -30,7 +30,7 @@
import net.yacy.kelondro.order.NaturalOrder;


public class BinSearch {
public final class BinSearch {

private final byte[] chunks;
private final int chunksize;
Expand All @@ -43,11 +43,11 @@ public BinSearch(final byte[] chunks, final int chunksize) {
this.count = chunks.length / chunksize;
}

public boolean contains(final byte[] t) {
public final boolean contains(final byte[] t) {
return contains(t, 0, this.count);
}

private synchronized boolean contains(final byte[] t, final int beginPos, final int endPos) {
private final synchronized boolean contains(final byte[] t, final int beginPos, final int endPos) {
// the endPos is exclusive, beginPos is inclusive
// this method is synchronized to make the use of the buffer possible
assert t.length == this.chunksize;
Expand All @@ -61,11 +61,11 @@ private synchronized boolean contains(final byte[] t, final int beginPos, final
return false;
}

public int size() {
public final int size() {
return count;
}

public byte[] get(final int element) {
public final byte[] get(final int element) {
final byte[] a = new byte[chunksize];
System.arraycopy(this.chunks, element * this.chunksize, a, 0, chunksize);
return a;
Expand Down
54 changes: 27 additions & 27 deletions source/net/yacy/kelondro/index/Cache.java
Expand Up @@ -41,7 +41,7 @@
import net.yacy.kelondro.util.MemoryControl;


public class Cache implements ObjectIndex, Iterable<Row.Entry> {
public final class Cache implements ObjectIndex, Iterable<Row.Entry> {

// this is a combined read cache and write buffer
// we maintain four tables:
Expand Down Expand Up @@ -91,15 +91,15 @@ public final int cacheObjectChunkSize() {
return index.row().objectsize;
}

public int writeBufferSize() {
public final int writeBufferSize() {
return 0;
}

public static long getMemStopGrow() {
public final static long getMemStopGrow() {
return memStopGrow ;
}

public static long getMemStartShrink() {
public final static long getMemStartShrink() {
return memStartShrink ;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ private final Map<String, String> memoryStats() {
* checks for space in the miss cache
* @return true if it is allowed to write into this cache
*/
private boolean checkMissSpace() {
private final boolean checkMissSpace() {
// returns true if it is allowed to write into this cache
if (readMissCache == null) return false;
long available = MemoryControl.available();
Expand All @@ -163,7 +163,7 @@ private boolean checkMissSpace() {
* checks for space in the hit cache
* @return true if it is allowed to write into this cache
*/
private boolean checkHitSpace() {
private final boolean checkHitSpace() {
// returns true if it is allowed to write into this cache
if (readHitCache == null) return false;
long available = MemoryControl.available();
Expand All @@ -174,18 +174,18 @@ private boolean checkHitSpace() {
return (available - 2 * 1024 * 1024 > readHitCache.memoryNeededForGrow());
}

public synchronized void clearCache() {
public final synchronized void clearCache() {
if (readMissCache != null) readMissCache.clear();
if (readHitCache != null) readHitCache.clear();
}

public synchronized void close() {
public final synchronized void close() {
index.close();
readHitCache = null;
readMissCache = null;
}

public synchronized boolean has(final byte[] key) {
public final synchronized boolean has(final byte[] key) {
// first look into the miss cache
if (readMissCache != null) {
if (readMissCache.get(key) == null) {
Expand All @@ -209,7 +209,7 @@ public synchronized boolean has(final byte[] key) {
return index.has(key);
}

public synchronized Row.Entry get(final byte[] key) throws IOException {
public final synchronized Row.Entry get(final byte[] key) throws IOException {
// first look into the miss cache
if (readMissCache != null) {
if (readMissCache.get(key) == null) {
Expand Down Expand Up @@ -250,7 +250,7 @@ public synchronized Row.Entry get(final byte[] key) throws IOException {
return entry;
}

public synchronized void put(final Row.Entry row) throws IOException {
public final synchronized void put(final Row.Entry row) throws IOException {
assert (row != null);
assert (row.columns() == row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
Expand Down Expand Up @@ -280,7 +280,7 @@ public synchronized void put(final Row.Entry row) throws IOException {
}
}

public synchronized Row.Entry replace(final Row.Entry row) throws IOException {
public final synchronized Row.Entry replace(final Row.Entry row) throws IOException {
assert (row != null);
assert (row.columns() == row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
Expand Down Expand Up @@ -313,7 +313,7 @@ public synchronized Row.Entry replace(final Row.Entry row) throws IOException {
return entry;
}

public synchronized void addUnique(final Row.Entry row) throws IOException {
public final synchronized void addUnique(final Row.Entry row) throws IOException {
assert (row != null);
assert (row.columns() == row().columns());
//assert (!(serverLog.allZero(row.getColBytes(index.primarykey()))));
Expand Down Expand Up @@ -342,7 +342,7 @@ public synchronized void addUnique(final Row.Entry row) throws IOException {
}
}

public synchronized void addUnique(final Row.Entry row, final Date entryDate) throws IOException {
public final synchronized void addUnique(final Row.Entry row, final Date entryDate) throws IOException {
if (entryDate == null) {
addUnique(row);
return;
Expand All @@ -368,17 +368,17 @@ public synchronized void addUnique(final Row.Entry row, final Date entryDate) th
}
}

public synchronized void addUnique(final List<Row.Entry> rows) throws IOException {
public final synchronized void addUnique(final List<Row.Entry> rows) throws IOException {
final Iterator<Row.Entry> i = rows.iterator();
while (i.hasNext()) addUnique(i.next());
}

public synchronized ArrayList<RowCollection> removeDoubles() throws IOException {
public final synchronized ArrayList<RowCollection> removeDoubles() throws IOException {
return index.removeDoubles();
// todo: remove reported entries from the cache!!!
}

public synchronized Row.Entry remove(final byte[] key) throws IOException {
public final synchronized Row.Entry remove(final byte[] key) throws IOException {
checkMissSpace();

// add entry to miss-cache
Expand Down Expand Up @@ -407,7 +407,7 @@ public synchronized Row.Entry remove(final byte[] key) throws IOException {
return index.remove(key);
}

public synchronized Row.Entry removeOne() throws IOException {
public final synchronized Row.Entry removeOne() throws IOException {

checkMissSpace();

Expand All @@ -425,44 +425,44 @@ public synchronized Row.Entry removeOne() throws IOException {
return entry;
}

public synchronized Row row() {
public final synchronized Row row() {
return index.row();
}

public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
public final synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
return index.keys(up, firstKey);
}

public synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
public final synchronized CloneableIterator<Row.Entry> rows(final boolean up, final byte[] firstKey) throws IOException {
return index.rows(up, firstKey);
}

public Iterator<Entry> iterator() {
public final Iterator<Entry> iterator() {
try {
return rows();
} catch (IOException e) {
return null;
}
}

public synchronized CloneableIterator<Row.Entry> rows() throws IOException {
public final synchronized CloneableIterator<Row.Entry> rows() throws IOException {
return index.rows();
}

public int size() {
public final int size() {
return index.size();
}

public String filename() {
public final String filename() {
return index.filename();
}

public void clear() throws IOException {
public final void clear() throws IOException {
this.index.clear();
init();
}

public void deleteOnExit() {
public final void deleteOnExit() {
this.index.deleteOnExit();
}

Expand Down
8 changes: 4 additions & 4 deletions source/net/yacy/kelondro/index/Column.java
Expand Up @@ -29,7 +29,7 @@

import net.yacy.kelondro.util.kelondroException;

public class Column {
public final class Column {

public static final int celltype_undefined = 0;
public static final int celltype_boolean = 1;
Expand Down Expand Up @@ -192,7 +192,7 @@ public Column(String celldef) {
}
}

public String toString() {
public final String toString() {
final StringBuilder s = new StringBuilder();
switch (celltype) {
case celltype_undefined:
Expand Down Expand Up @@ -245,7 +245,7 @@ public String toString() {
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
public final int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + celltype;
Expand All @@ -260,7 +260,7 @@ public int hashCode() {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public final boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
Expand Down
15 changes: 7 additions & 8 deletions source/net/yacy/kelondro/index/ConcurrentARC.java
Expand Up @@ -34,11 +34,10 @@
* at the same size.
*/

public class ConcurrentARC<K, V> implements ARC<K, V> {
public final class ConcurrentARC<K, V> implements ARC<K, V> {

protected int cacheSize;
private int mask;
private ARC<K, V> arc[];
private final ARC<K, V> arc[];

@SuppressWarnings("unchecked")
public ConcurrentARC(final int cacheSize, int partitions) {
Expand All @@ -54,7 +53,7 @@ public ConcurrentARC(final int cacheSize, int partitions) {
* @param s
* @param v
*/
public void put(K s, V v) {
public final void put(K s, V v) {
this.arc[s.hashCode() & mask].put(s, v);
}

Expand All @@ -63,7 +62,7 @@ public void put(K s, V v) {
* @param s
* @return the value
*/
public V get(K s) {
public final V get(K s) {
return this.arc[s.hashCode() & mask].get(s);
}

Expand All @@ -72,7 +71,7 @@ public V get(K s) {
* @param s
* @return
*/
public boolean containsKey(K s) {
public final boolean containsKey(K s) {
return this.arc[s.hashCode() & mask].containsKey(s);
}

Expand All @@ -81,14 +80,14 @@ public boolean containsKey(K s) {
* @param s
* @return the old value
*/
public V remove(K s) {
public final V remove(K s) {
return this.arc[s.hashCode() & mask].remove(s);
}

/**
* clear the cache
*/
public void clear() {
public final void clear() {
for (ARC<K, V> a: this.arc) a.clear();
}
}

0 comments on commit 2a7fe35

Please sign in to comment.