From f4ff0f795da52f2eb636a45095d7a92e24555179 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 27 Mar 2008 08:05:08 +0000 Subject: [PATCH] Performance improvement for Index Database. --- .../cdt/internal/core/pdom/db/Chunk.java | 34 +++++++++---------- .../cdt/internal/core/pdom/db/Database.java | 1 + 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java index a64a97a695a..0ed179b604f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems and others. + * Copyright (c) 2005, 2008 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -58,29 +58,29 @@ final class Chunk { public void putByte(final int offset, final byte value) { assert fLocked; fDirty= true; - fBuffer[offset % Database.CHUNK_SIZE]= value; + fBuffer[offset & Database.OFFSET_IN_CHUNK_MASK]= value; } public byte getByte(final int offset) { - return fBuffer[offset % Database.CHUNK_SIZE]; + return fBuffer[offset & Database.OFFSET_IN_CHUNK_MASK]; } public byte[] getBytes(final int offset, final int length) { final byte[] bytes = new byte[length]; - System.arraycopy(fBuffer, offset % Database.CHUNK_SIZE, bytes, 0, length); + System.arraycopy(fBuffer, offset & Database.OFFSET_IN_CHUNK_MASK, bytes, 0, length); return bytes; } public void putBytes(final int offset, final byte[] bytes) { assert fLocked; fDirty= true; - System.arraycopy(bytes, 0, fBuffer, offset % Database.CHUNK_SIZE, bytes.length); + System.arraycopy(bytes, 0, fBuffer, offset & Database.OFFSET_IN_CHUNK_MASK, bytes.length); } public void putInt(final int offset, final int value) { assert fLocked; fDirty= true; - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; fBuffer[idx]= (byte)(value >> 24); fBuffer[++idx]= (byte)(value >> 16); fBuffer[++idx]= (byte)(value >> 8); @@ -88,7 +88,7 @@ final class Chunk { } public int getInt(final int offset) { - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; return ((fBuffer[idx] & 0xff) << 24) | ((fBuffer[++idx] & 0xff) << 16) | ((fBuffer[++idx] & 0xff) << 8) | @@ -98,14 +98,14 @@ final class Chunk { public void put3ByteUnsignedInt(final int offset, final int value) { assert fLocked; fDirty= true; - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; fBuffer[idx]= (byte)(value >> 16); fBuffer[++idx]= (byte)(value >> 8); fBuffer[++idx]= (byte)(value); } public int get3ByteUnsignedInt(final int offset) { - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; return ((fBuffer[idx] & 0xff) << 16) | ((fBuffer[++idx] & 0xff) << 8) | ((fBuffer[++idx] & 0xff) << 0); @@ -114,18 +114,18 @@ final class Chunk { public void putShort(final int offset, final short value) { assert fLocked; fDirty= true; - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; fBuffer[idx]= (byte)(value >> 8); fBuffer[++idx]= (byte)(value); } public short getShort(final int offset) { - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; return (short) (((fBuffer[idx] << 8) | (fBuffer[++idx] & 0xff))); } public long getLong(final int offset) { - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; return ((((long)fBuffer[idx] & 0xff) << 56) | (((long)fBuffer[++idx] & 0xff) << 48) | (((long)fBuffer[++idx] & 0xff) << 40) | @@ -139,7 +139,7 @@ final class Chunk { public void putLong(final int offset, final long value) { assert fLocked; fDirty= true; - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; fBuffer[idx]= (byte)(value >> 56); fBuffer[++idx]= (byte)(value >> 48); @@ -154,26 +154,26 @@ final class Chunk { public void putChar(final int offset, final char value) { assert fLocked; fDirty= true; - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; fBuffer[idx]= (byte)(value >> 8); fBuffer[++idx]= (byte)(value); } public char getChar(final int offset) { - int idx= offset % Database.CHUNK_SIZE; + int idx= offset & Database.OFFSET_IN_CHUNK_MASK; return (char) (((fBuffer[idx] << 8) | (fBuffer[++idx] & 0xff))); } public void getCharArray(final int offset, final char[] result) { final ByteBuffer buf= ByteBuffer.wrap(fBuffer); - buf.position(offset % Database.CHUNK_SIZE); + buf.position(offset & Database.OFFSET_IN_CHUNK_MASK); buf.asCharBuffer().get(result); } void clear(final int offset, final int length) { assert fLocked; fDirty= true; - int idx= (offset % Database.CHUNK_SIZE); + int idx= (offset & Database.OFFSET_IN_CHUNK_MASK); final int end= idx + length; for (; idx < end; idx++) { fBuffer[idx]= 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java index 1616cbbf20c..7557a5a6dc2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java @@ -65,6 +65,7 @@ public class Database { // public for tests only, you shouldn't need these public static final int INT_SIZE = 4; public static final int CHUNK_SIZE = 1024 * 4; + public static final int OFFSET_IN_CHUNK_MASK= CHUNK_SIZE-1; public static final int BLOCK_HEADER_SIZE= 2; public static final int BLOCK_SIZE_DELTA= 8; public static final int MIN_BLOCK_DELTAS = 2; // a block must at least be 2 + 2*4 bytes to link the free blocks.