Skip to content
Permalink
Browse files

Core: Drop UnsafeUtils.

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 22, 2014
1 parent 72247aa commit 3c57800a6f5143178b671eb708c7e3a95b792bdd
@@ -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;
@@ -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)) {
@@ -19,7 +19,7 @@

package org.elasticsearch.common.hash;

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


/**
@@ -41,7 +41,7 @@
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) {
@@ -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);
@@ -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;
}
}
@@ -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;
}
}

This file was deleted.

Oops, something went wrong.
@@ -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;
@@ -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) {

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 3c57800

Please sign in to comment.
You can’t perform that action at this time.