From 1fd9395de4046946ce1e1e929b57360d80e5083e Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 26 Jan 2012 17:28:13 +0400 Subject: [PATCH] less garbage and synchronization during building indexed --- .../intellij/images/util/ImageInfoReader.java | 3 +- .../psi/stubs/SerializedStubTree.java | 5 +- .../BufferExposingByteArrayInputStream.java | 7 +- .../BufferExposingByteArrayOutputStream.java | 16 ++- .../com/intellij/util/io/IntToIntBtree.java | 11 +- .../util/io/PersistentBTreeEnumerator.java | 17 +-- .../intellij/util/io/PersistentHashMap.java | 111 +++++++----------- .../io/PersistentHashMapValueStorage.java | 7 +- .../util/io/UnsyncByteArrayInputStream.java | 69 +++++++++++ .../util/io/UnsyncByteArrayOutputStream.java | 77 ++++++++++++ .../util/io/storage/AbstractStorage.java | 3 +- .../properties/xml/XmlPropertiesIndex.java | 7 +- .../com/intellij/util/xml/DomFileIndex.java | 4 +- .../intellij/xml/index/XmlNamespaceIndex.java | 4 +- .../intellij/xml/index/XmlTagNamesIndex.java | 4 +- 15 files changed, 234 insertions(+), 111 deletions(-) create mode 100644 platform/util/src/com/intellij/util/io/UnsyncByteArrayInputStream.java create mode 100644 platform/util/src/com/intellij/util/io/UnsyncByteArrayOutputStream.java diff --git a/images/src/org/intellij/images/util/ImageInfoReader.java b/images/src/org/intellij/images/util/ImageInfoReader.java index 1c809bbba28f..7dd764faa328 100644 --- a/images/src/org/intellij/images/util/ImageInfoReader.java +++ b/images/src/org/intellij/images/util/ImageInfoReader.java @@ -16,6 +16,7 @@ package org.intellij.images.util; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.io.UnsyncByteArrayInputStream; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,7 +66,7 @@ public class ImageInfoReader { @Nullable private static Info read(@NotNull final byte[] data) { - final DataInputStream is = new DataInputStream(new ByteArrayInputStream(data)); + final DataInputStream is = new DataInputStream(new UnsyncByteArrayInputStream(data)); try { return readFileData(is); } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java b/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java index abaf63828b69..d7423c8420b2 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/SerializedStubTree.java @@ -19,7 +19,8 @@ */ package com.intellij.psi.stubs; -import java.io.ByteArrayInputStream; +import com.intellij.util.io.UnsyncByteArrayInputStream; + import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -45,7 +46,7 @@ public class SerializedStubTree { } public StubElement getStub() { - return SerializationManager.getInstance().deserialize(new ByteArrayInputStream(myBytes)); + return SerializationManager.getInstance().deserialize(new UnsyncByteArrayInputStream(myBytes)); } public boolean equals(final Object that) { diff --git a/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayInputStream.java b/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayInputStream.java index d0c9412efe07..9a2efb3e2ba7 100644 --- a/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayInputStream.java +++ b/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayInputStream.java @@ -15,17 +15,16 @@ */ package com.intellij.openapi.util.io; +import com.intellij.util.io.UnsyncByteArrayInputStream; import org.jetbrains.annotations.NotNull; -import java.io.ByteArrayInputStream; - -public class BufferExposingByteArrayInputStream extends ByteArrayInputStream { +public class BufferExposingByteArrayInputStream extends UnsyncByteArrayInputStream { public BufferExposingByteArrayInputStream(@NotNull byte[] bytes) { super(bytes); } @NotNull public byte[] getInternalBuffer() { - return buf; + return myBuffer; } } diff --git a/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayOutputStream.java b/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayOutputStream.java index 61fe2ea73020..990088c1842f 100644 --- a/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayOutputStream.java +++ b/platform/util/src/com/intellij/openapi/util/io/BufferExposingByteArrayOutputStream.java @@ -15,13 +15,11 @@ */ package com.intellij.openapi.util.io; +import com.intellij.util.io.UnsyncByteArrayOutputStream; import org.jetbrains.annotations.NotNull; -import java.io.ByteArrayOutputStream; - -public class BufferExposingByteArrayOutputStream extends ByteArrayOutputStream { - public BufferExposingByteArrayOutputStream() { - } +public class BufferExposingByteArrayOutputStream extends UnsyncByteArrayOutputStream { + public BufferExposingByteArrayOutputStream() {} public BufferExposingByteArrayOutputStream(int size) { super(size); @@ -29,14 +27,14 @@ public class BufferExposingByteArrayOutputStream extends ByteArrayOutputStream { @NotNull public byte[] getInternalBuffer() { - return buf; + return myBuffer; } // moves back the written bytes pointer by {@link #size}, to "unwrite" last {@link #size} bytes public int backOff(int size) { assert size >= 0 : size; - count -= size; - assert count >= 0 : count; - return count; + myCount -= size; + assert myCount >= 0 : myCount; + return myCount; } } diff --git a/platform/util/src/com/intellij/util/io/IntToIntBtree.java b/platform/util/src/com/intellij/util/io/IntToIntBtree.java index 8df25adaa3b8..5c73f192038d 100644 --- a/platform/util/src/com/intellij/util/io/IntToIntBtree.java +++ b/platform/util/src/com/intellij/util/io/IntToIntBtree.java @@ -2,7 +2,6 @@ package com.intellij.util.io; import com.intellij.openapi.util.io.FileUtil; import gnu.trove.TIntIntHashMap; -import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -130,10 +129,11 @@ class IntToIntBtree { return pageStart; } - public @Nullable Integer get(int key) { + public boolean get(int key, int[] result) { if (hasCachedMappings) { if (myCachedMappings.containsKey(key)) { - return myCachedMappings.get(key); + result[0] = myCachedMappings.get(key); + return true; } } @@ -141,8 +141,9 @@ class IntToIntBtree { currentIndexNode.setAddress(root.address); int index = currentIndexNode.locate(key, false); - if (index < 0) return null; - return currentIndexNode.addressAt(index); + if (index < 0) return false; + result[0] = currentIndexNode.addressAt(index); + return true; } public void put(int key, int value) { diff --git a/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java b/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java index f99784a9d79d..5c21065d3a33 100644 --- a/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java +++ b/platform/util/src/com/intellij/util/io/PersistentBTreeEnumerator.java @@ -186,9 +186,11 @@ public class PersistentBTreeEnumerator extends PersistentEnumeratorBase 0) { if (!p.process(record)) return false; } else { @@ -259,22 +261,23 @@ public class PersistentBTreeEnumerator extends PersistentEnumeratorBase 0) { @@ -309,7 +312,7 @@ public class PersistentBTreeEnumerator extends PersistentEnumeratorBase extends PersistentEnumeratorDelegate< super(new BufferExposingByteArrayOutputStream()); } - public int getBufferSize() { - return ((ByteArrayOutputStream)out).size(); + private void reset() { + ((UnsyncByteArrayOutputStream)out).reset(); } - public void writeTo(OutputStream stream) throws IOException { - ((ByteArrayOutputStream)out).writeTo(stream); - } - - public void reset() { - ((ByteArrayOutputStream)out).reset(); - } - - public byte[] toByteArray() { - return ((ByteArrayOutputStream)out).toByteArray(); - } - - public ByteSequence getInternalBuffer() { - final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream)out; - return new ByteSequence(_out.getInternalBuffer(), 0, _out.size()); + private BufferExposingByteArrayOutputStream getInternalBuffer() { + return (BufferExposingByteArrayOutputStream)out; } } @@ -110,16 +97,14 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< protected void onDropFromCache(final Key key, final AppendStream value) { synchronized (PersistentEnumerator.ourLock) { try { - final ByteSequence bytes = value.getInternalBuffer(); + final BufferExposingByteArrayOutputStream bytes = value.getInternalBuffer(); final int id = enumerate(key); - HeaderRecord oldHeaderRecord = readValueId(id); + long oldHeaderRecord = readValueId(id); - HeaderRecord headerRecord = new HeaderRecord( - myValueStorage.appendBytes(bytes, oldHeaderRecord.address) - ); + long headerRecord = myValueStorage.appendBytes(bytes.getInternalBuffer(), 0, bytes.size(), oldHeaderRecord); updateValueId(id, headerRecord, oldHeaderRecord, key, 0); - if (oldHeaderRecord == HeaderRecord.EMPTY) { + if (oldHeaderRecord == NULL_ADDR) { myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; } @@ -266,18 +251,18 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< final AppendStream record = new AppendStream(); myValueExternalizer.save(record, value); - final ByteSequence bytes = record.getInternalBuffer(); + final BufferExposingByteArrayOutputStream bytes = record.getInternalBuffer(); final int id = enumerate(key); - HeaderRecord oldheader = readValueId(id); - if (oldheader != HeaderRecord.EMPTY) { + long oldheader = readValueId(id); + if (oldheader != NULL_ADDR) { myLiveAndGarbageKeysCounter++; } else { myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; } - HeaderRecord header = new HeaderRecord(myValueStorage.appendBytes(bytes, 0)); + long header = myValueStorage.appendBytes(bytes.getInternalBuffer(), 0, bytes.size(), 0); updateValueId(id, header, oldheader, key, 0); } @@ -330,41 +315,39 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< myAppendCache.clear(); return myEnumerator.processAllDataObject(processor, new PersistentEnumerator.DataFilter() { public boolean accept(final int id) { - return readValueId(id).address != NULL_ADDR; + return readValueId(id) != NULL_ADDR; } }); } } - public final Value get(Key key) throws IOException { + public final @Nullable Value get(Key key) throws IOException { synchronized (myEnumerator) { return doGet(key); } } - protected Value doGet(Key key) throws IOException { + protected @Nullable Value doGet(Key key) throws IOException { synchronized (PersistentEnumerator.ourLock) { myAppendCache.remove(key); final int id = tryEnumerate(key); if (id == PersistentEnumerator.NULL_ID) { return null; } - final HeaderRecord oldHeader = readValueId(id); - if (oldHeader.address == PersistentEnumerator.NULL_ID) { + final long oldHeader = readValueId(id); + if (oldHeader == PersistentEnumerator.NULL_ID) { return null; } - Pair readResult = myValueStorage.readBytes(oldHeader.address); - if (readResult.first != null && readResult.first != oldHeader.address) { + Pair readResult = myValueStorage.readBytes(oldHeader); + if (readResult.first != null && readResult.first != oldHeader) { myEnumerator.markDirty(true); - updateValueId(id, new HeaderRecord(readResult.first), oldHeader, key, 0); - if (oldHeader != HeaderRecord.EMPTY) { - myLiveAndGarbageKeysCounter++; - } + updateValueId(id, readResult.first, oldHeader, key, 0); + myLiveAndGarbageKeysCounter++; } - final DataInputStream input = new DataInputStream(new ByteArrayInputStream(readResult.second)); + final DataInputStream input = new DataInputStream(new UnsyncByteArrayInputStream(readResult.second)); try { return myValueExternalizer.read(input); } @@ -387,7 +370,7 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< if (id == PersistentEnumerator.NULL_ID) { return false; } - return readValueId(id).address != NULL_ADDR; + return readValueId(id) != NULL_ADDR; } } @@ -406,12 +389,12 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< } myEnumerator.markDirty(true); - final HeaderRecord record = readValueId(id); - if (record != HeaderRecord.EMPTY) { + final long record = readValueId(id); + if (record != NULL_ADDR) { myLiveAndGarbageKeysCounter++; } - updateValueId(id, HeaderRecord.EMPTY, record, key, 0); + updateValueId(id, NULL_ADDR, record, key, 0); } } @@ -473,10 +456,10 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< traverseAllRecords(new PersistentEnumerator.RecordsProcessor() { public boolean process(final int keyId) throws IOException { - final HeaderRecord record = readValueId(keyId); - if (record.address != NULL_ADDR) { - Pair readResult = myValueStorage.readBytes(record.address); - HeaderRecord value = new HeaderRecord(newStorage.appendBytes(new ByteSequence(readResult.second), 0)); + final long record = readValueId(keyId); + if (record != NULL_ADDR) { + Pair readResult = myValueStorage.readBytes(record); + long value = newStorage.appendBytes(new ByteSequence(readResult.second), 0); updateValueId(keyId, value, record, null, getCurrentKey()); myLiveAndGarbageKeysCounter += LIVE_KEY_MASK; } @@ -496,10 +479,10 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< } } - private HeaderRecord readValueId(final int keyId) { + private long readValueId(final int keyId) { long address = myEnumerator.myStorage.getInt(keyId + myParentValueRefOffset); if (address == 0 || address == -POSITIVE_VALUE_SHIFT) { - return HeaderRecord.EMPTY; + return NULL_ADDR; } if (address < 0) { @@ -509,7 +492,7 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< address = ((address << 32) + value) & ~USED_LONG_VALUE_MASK; } - return new HeaderRecord(address); + return address; } private int smallKeys; @@ -517,19 +500,19 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< private int transformedKeys; private int requests; - private int updateValueId(int keyId, HeaderRecord value, HeaderRecord oldValue, @Nullable Key key, int processingKey) throws IOException { - final boolean newKey = oldValue == null || oldValue.address == NULL_ADDR; + private int updateValueId(int keyId, long value, long oldValue, @Nullable Key key, int processingKey) throws IOException { + final boolean newKey = oldValue == NULL_ADDR; if (newKey) ++requests; boolean defaultSizeInfo = true; if (myCanReEnumerate) { - if (canUseIntAddressForNewRecord(value.address)) { + if (canUseIntAddressForNewRecord(value)) { defaultSizeInfo = false; - myEnumerator.myStorage.putInt(keyId + myParentValueRefOffset, -(int)(value.address + POSITIVE_VALUE_SHIFT)); + myEnumerator.myStorage.putInt(keyId + myParentValueRefOffset, -(int)(value + POSITIVE_VALUE_SHIFT)); if (newKey) ++smallKeys; } else { if (newKey && myWatermarkId == 0) myWatermarkId = keyId; - if (keyId < myWatermarkId && (oldValue == null || canUseIntAddressForNewRecord(oldValue.address))) { + if (keyId < myWatermarkId && (oldValue == NULL_ADDR || canUseIntAddressForNewRecord(oldValue))) { // keyId is result of enumerate, if we do reenumerate then it is no longer accessible unless somebody cached it myIntAddressForNewRecord = false; keyId = myEnumerator.reenumerate(key == null ? myEnumerator.getValue(keyId, processingKey) : key); @@ -539,7 +522,7 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< } if (defaultSizeInfo) { - myEnumerator.myStorage.putLong(keyId + myParentValueRefOffset, value.address | USED_LONG_VALUE_MASK); + myEnumerator.myStorage.putLong(keyId + myParentValueRefOffset, value | USED_LONG_VALUE_MASK); if (newKey) ++largeKeys; } @@ -548,21 +531,11 @@ public class PersistentHashMap extends PersistentEnumeratorDelegate< ",@"+getBaseFile().getPath()); } if (doHardConsistencyChecks) { - HeaderRecord checkRecord = readValueId(keyId); - if (checkRecord.address != value.address) { - assert false:value.address; + long checkRecord = readValueId(keyId); + if (checkRecord != value) { + assert false:value; } } return keyId; } - - private static class HeaderRecord { - final long address; - - HeaderRecord(long address) { - this.address = address; - } - - static final HeaderRecord EMPTY = new HeaderRecord(NULL_ADDR); - } } diff --git a/platform/util/src/com/intellij/util/io/PersistentHashMapValueStorage.java b/platform/util/src/com/intellij/util/io/PersistentHashMapValueStorage.java index 6edddcd02ace..26daa4379a9c 100644 --- a/platform/util/src/com/intellij/util/io/PersistentHashMapValueStorage.java +++ b/platform/util/src/com/intellij/util/io/PersistentHashMapValueStorage.java @@ -79,10 +79,13 @@ public class PersistentHashMapValueStorage { private static final int INT_LENGTH_LONG_ADDRESS = 4 + 8; public long appendBytes(ByteSequence data, long prevChunkAddress) throws IOException { + return appendBytes(data.getBytes(), data.getOffset(), data.getLength(), prevChunkAddress); + } + + public long appendBytes(byte[] data, int offset, int dataLength, long prevChunkAddress) throws IOException { assert !myCompactionMode; long result = mySize; final CacheValue appender = ourAppendersCache.get(myPath); - int dataLength = data.getLength(); int serviceFieldsSizeIncrease; try { @@ -102,7 +105,7 @@ public class PersistentHashMapValueStorage { dataOutputStream.writeLong(prevChunkAddress); serviceFieldsSizeIncrease = INT_LENGTH_LONG_ADDRESS; } - dataOutputStream.write(data.getBytes(), data.getOffset(), dataLength); + dataOutputStream.write(data, offset, dataLength); if (requests % IOStatistics.KEYS_FACTOR == 0 && IOStatistics.DEBUG) { IOStatistics.dump("Small writes:"+smallWritesCount +", bytes:"+smallWrites + ", largeWrites:"+largeWritesCount + ", bytes:"+largeWrites+", total:"+requests + "@"+myFile.getPath()); diff --git a/platform/util/src/com/intellij/util/io/UnsyncByteArrayInputStream.java b/platform/util/src/com/intellij/util/io/UnsyncByteArrayInputStream.java new file mode 100644 index 000000000000..c22a9ecb0818 --- /dev/null +++ b/platform/util/src/com/intellij/util/io/UnsyncByteArrayInputStream.java @@ -0,0 +1,69 @@ +package com.intellij.util.io; + +import java.io.InputStream; + +public class UnsyncByteArrayInputStream extends InputStream { + protected byte[] myBuffer; + private int myPosition; + private int myCount; + private int myMarkedPosition; + + public UnsyncByteArrayInputStream(byte buf[]) { + this.myBuffer = buf; + this.myPosition = 0; + this.myCount = buf.length; + } + + public int read() { + return (myPosition < myCount) ? (myBuffer[myPosition++] & 0xff) : -1; + } + + public int read(byte b[], int off, int len) { + if (b == null) { + throw new NullPointerException(); + } else if (off < 0 || len < 0 || len > b.length - off) { + throw new IndexOutOfBoundsException(); + } + if (myPosition >= myCount) { + return -1; + } + if (myPosition + len > myCount) { + len = myCount - myPosition; + } + if (len <= 0) { + return 0; + } + System.arraycopy(myBuffer, myPosition, b, off, len); + myPosition += len; + return len; + } + + public long skip(long n) { + if (myPosition + n > myCount) { + n = myCount - myPosition; + } + if (n < 0) { + return 0; + } + myPosition += n; + return n; + } + + public int available() { + return myCount - myPosition; + } + + @Override + public boolean markSupported() { + return true; + } + + @Override + public void mark(int readlimit) { + myMarkedPosition = myPosition; + } + + public void reset() { + myPosition = myMarkedPosition; + } +} diff --git a/platform/util/src/com/intellij/util/io/UnsyncByteArrayOutputStream.java b/platform/util/src/com/intellij/util/io/UnsyncByteArrayOutputStream.java new file mode 100644 index 000000000000..3ba1db36b94b --- /dev/null +++ b/platform/util/src/com/intellij/util/io/UnsyncByteArrayOutputStream.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.io; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Arrays; + +public class UnsyncByteArrayOutputStream extends OutputStream { + protected byte[] myBuffer; + protected int myCount; + + public UnsyncByteArrayOutputStream() { + this(32); + } + + public UnsyncByteArrayOutputStream(int size) { + myBuffer = new byte[size]; + } + + public void write(int b) { + int newcount = myCount + 1; + if (newcount > myBuffer.length) { + myBuffer = Arrays.copyOf(myBuffer, Math.max(myBuffer.length << 1, newcount)); + } + myBuffer[myCount] = (byte)b; + myCount = newcount; + } + + public void write(byte b[], int off, int len) { + if ((off < 0) || (off > b.length) || (len < 0) || + ((off + len) > b.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + int newcount = myCount + len; + if (newcount > myBuffer.length) { + myBuffer = Arrays.copyOf(myBuffer, Math.max(myBuffer.length << 1, newcount)); + } + System.arraycopy(b, off, myBuffer, myCount, len); + myCount = newcount; + } + + public void writeTo(OutputStream out) throws IOException { + out.write(myBuffer, 0, myCount); + } + + public void reset() { + myCount = 0; + } + + public byte[] toByteArray() { + return Arrays.copyOf(myBuffer, myCount); + } + + public int size() { + return myCount; + } + + public String toString() { + return new String(myBuffer, 0, myCount); + } +} diff --git a/platform/util/src/com/intellij/util/io/storage/AbstractStorage.java b/platform/util/src/com/intellij/util/io/storage/AbstractStorage.java index 8051d48d0b82..e98173172044 100644 --- a/platform/util/src/com/intellij/util/io/storage/AbstractStorage.java +++ b/platform/util/src/com/intellij/util/io/storage/AbstractStorage.java @@ -28,6 +28,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.io.PagePool; import com.intellij.util.io.RecordDataOutput; +import com.intellij.util.io.UnsyncByteArrayInputStream; import org.jetbrains.annotations.NonNls; import java.io.*; @@ -228,7 +229,7 @@ public abstract class AbstractStorage implements Disposable, Forceable { public DataInputStream readStream(int record) throws IOException { final byte[] bytes = readBytes(record); - return new DataInputStream(new ByteArrayInputStream(bytes)); + return new DataInputStream(new UnsyncByteArrayInputStream(bytes)); } protected byte[] readBytes(int record) throws IOException { diff --git a/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java b/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java index a0473e9fa33b..827c08987a22 100644 --- a/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java +++ b/plugins/properties/src/com/intellij/lang/properties/xml/XmlPropertiesIndex.java @@ -5,10 +5,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.StreamUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.indexing.*; -import com.intellij.util.io.DataExternalizer; -import com.intellij.util.io.EnumeratorStringDescriptor; -import com.intellij.util.io.IOUtil; -import com.intellij.util.io.KeyDescriptor; +import com.intellij.util.io.*; import com.intellij.util.xml.NanoXmlUtil; import net.n3.nanoxml.StdXMLReader; import org.jetbrains.annotations.NotNull; @@ -91,7 +88,7 @@ public class XmlPropertiesIndex extends FileBasedIndexExtension{ @NotNull public Map map(final FileContent inputData) { final Set namespaces = new THashSet(); - final XmlFileHeader header = NanoXmlUtil.parseHeader(new ByteArrayInputStream(inputData.getContent())); + final XmlFileHeader header = NanoXmlUtil.parseHeader(new UnsyncByteArrayInputStream(inputData.getContent())); ContainerUtil.addIfNotNull(header.getPublicId(), namespaces); ContainerUtil.addIfNotNull(header.getSystemId(), namespaces); ContainerUtil.addIfNotNull(header.getRootTagNamespace(), namespaces); diff --git a/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java b/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java index 8cd41a372f2e..5af871e438af 100644 --- a/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java +++ b/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java @@ -24,10 +24,10 @@ import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileContent; import com.intellij.util.indexing.ID; import com.intellij.util.io.DataExternalizer; +import com.intellij.util.io.UnsyncByteArrayInputStream; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.ByteArrayInputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -67,7 +67,7 @@ public class XmlNamespaceIndex extends XmlIndex { return new DataIndexer() { @NotNull public Map map(final FileContent inputData) { - final String ns = XsdNamespaceBuilder.computeNamespace(new ByteArrayInputStream(inputData.getContent())); + final String ns = XsdNamespaceBuilder.computeNamespace(new UnsyncByteArrayInputStream(inputData.getContent())); final HashMap map = new HashMap(2); if (ns != null) { map.put(ns, ""); diff --git a/xml/impl/src/com/intellij/xml/index/XmlTagNamesIndex.java b/xml/impl/src/com/intellij/xml/index/XmlTagNamesIndex.java index b18d184ca698..a8d1901574a3 100644 --- a/xml/impl/src/com/intellij/xml/index/XmlTagNamesIndex.java +++ b/xml/impl/src/com/intellij/xml/index/XmlTagNamesIndex.java @@ -20,9 +20,9 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.HashMap; import com.intellij.util.indexing.*; import com.intellij.util.io.DataExternalizer; +import com.intellij.util.io.UnsyncByteArrayInputStream; import org.jetbrains.annotations.NotNull; -import java.io.ByteArrayInputStream; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -50,7 +50,7 @@ public class XmlTagNamesIndex extends XmlIndex { return new DataIndexer() { @NotNull public Map map(final FileContent inputData) { - final Collection tags = XsdTagNameBuilder.computeTagNames(new ByteArrayInputStream(inputData.getContent())); + final Collection tags = XsdTagNameBuilder.computeTagNames(new UnsyncByteArrayInputStream(inputData.getContent())); if (tags != null && !tags.isEmpty()) { final HashMap map = new HashMap(tags.size()); for (String tag : tags) {