Skip to content

Commit

Permalink
Core: Drop UnsafeUtils.
Browse files Browse the repository at this point in the history
This class potentially does unaligned memory access and does not bring much
now that we switched to global ords for terms aggregations.

Close #6962
  • Loading branch information
jpountz committed Jul 23, 2014
1 parent 72247aa commit 3c57800
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 304 deletions.
10 changes: 2 additions & 8 deletions src/main/java/org/elasticsearch/common/bytes/BytesReference.java
Expand Up @@ -20,7 +20,6 @@

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.util.UnsafeUtils;
import org.jboss.netty.buffer.ChannelBuffer;

import java.io.IOException;
Expand All @@ -42,16 +41,11 @@ public static boolean bytesEqual(BytesReference a, BytesReference b) {
return false;
}

if (a.hasArray() && b.hasArray()) {
// court-circuit to compare several bytes at once
return UnsafeUtils.equals(a.array(), a.arrayOffset(), b.array(), b.arrayOffset(), a.length());
} else {
return slowBytesEquals(a, b);
}
return bytesEquals(a, b);
}

// pkg-private for testing
static boolean slowBytesEquals(BytesReference a, BytesReference b) {
static boolean bytesEquals(BytesReference a, BytesReference b) {
assert a.length() == b.length();
for (int i = 0, end = a.length(); i < end; ++i) {
if (a.get(i) != b.get(i)) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/elasticsearch/common/hash/MurmurHash3.java
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.common.hash;

import org.elasticsearch.common.util.UnsafeUtils;
import org.elasticsearch.common.util.ByteUtils;


/**
Expand All @@ -41,7 +41,7 @@ public static class Hash128 {
protected static long getblock(byte[] key, int offset, int index) {
int i_8 = index << 3;
int blockOffset = offset + i_8;
return UnsafeUtils.readLongLE(key, blockOffset);
return ByteUtils.readLongLE(key, blockOffset);
}

protected static long fmix(long k) {
Expand All @@ -68,8 +68,8 @@ public static Hash128 hash128(byte[] key, int offset, int length, long seed, Has
final int len16 = length & 0xFFFFFFF0; // higher multiple of 16 that is lower than or equal to length
final int end = offset + len16;
for (int i = offset; i < end; i += 16) {
long k1 = UnsafeUtils.readLongLE(key, i);
long k2 = UnsafeUtils.readLongLE(key, i + 8);
long k1 = ByteUtils.readLongLE(key, i);
long k2 = ByteUtils.readLongLE(key, i + 8);

k1 *= C1;
k1 = Long.rotateLeft(k1, 31);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/elasticsearch/common/util/BytesRefHash.java
Expand Up @@ -77,7 +77,7 @@ public long find(BytesRef key, int code) {
final long slot = slot(rehash(code), mask);
for (long index = slot; ; index = nextSlot(index, mask)) {
final long id = id(index);
if (id == -1L || UnsafeUtils.equals(key, get(id, spare))) {
if (id == -1L || key.bytesEquals(get(id, spare))) {
return id;
}
}
Expand All @@ -99,7 +99,7 @@ private long set(BytesRef key, int code, long id) {
append(id, key, code);
++size;
return id;
} else if (UnsafeUtils.equals(key, get(curId, spare))) {
} else if (key.bytesEquals(get(curId, spare))) {
return -1 - curId;
}
}
Expand Down
145 changes: 0 additions & 145 deletions src/main/java/org/elasticsearch/common/util/UnsafeUtils.java

This file was deleted.

Expand Up @@ -31,8 +31,8 @@
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.ByteArray;
import org.elasticsearch.common.util.ByteUtils;
import org.elasticsearch.common.util.IntArray;
import org.elasticsearch.common.util.UnsafeUtils;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -438,7 +438,7 @@ private long index (long bucket, int index) {

private int get(long bucket, int index) {
runLens.get(index(bucket, index), 4, readSpare);
return UnsafeUtils.readIntLE(readSpare.bytes, readSpare.offset);
return ByteUtils.readIntLE(readSpare.bytes, readSpare.offset);
}

private void set(long bucket, int index, int value) {
Expand Down

This file was deleted.

0 comments on commit 3c57800

Please sign in to comment.