forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ReactiveX#7 RingBitSet optimisation
* test coverage added + jacoco excludes for benchmark classes * Issue ReactiveX#7 RingBitSet optimisation + benchmark results * Issue ReactiveX#7 cleanup
- Loading branch information
1 parent
17b2197
commit 7b282af
Showing
9 changed files
with
223 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 0 additions & 103 deletions
103
src/jmh/java/io/github/robwin/circuitbreaker/CircularBufferBenchmark.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/io/github/robwin/circuitbreaker/internal/BitSetMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* | ||
* Copyright 2016 Robert Winkler and Bohdan Storozhuk | ||
* | ||
* 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 io.github.robwin.circuitbreaker.internal; | ||
|
||
/** | ||
* {@link BitSetMod} is simplified version of {@link java.util.BitSet}. | ||
* It has no dynamic allocation, expanding logic, boundary checks | ||
* and it's set method returns previous bit state. | ||
*/ | ||
class BitSetMod { | ||
|
||
private final static int ADDRESS_BITS_PER_WORD = 6; | ||
private final int size; | ||
private final long[] words; | ||
|
||
|
||
BitSetMod(final int capacity) { | ||
int countOfWordsRequired = wordIndex(capacity - 1) + 1; | ||
size = countOfWordsRequired << ADDRESS_BITS_PER_WORD; | ||
words = new long[countOfWordsRequired]; | ||
} | ||
|
||
/** | ||
* Given a bit index, return word index containing it. | ||
*/ | ||
private static int wordIndex(int bitIndex) { | ||
return bitIndex >> ADDRESS_BITS_PER_WORD; | ||
} | ||
|
||
/** | ||
* Sets the bit at the specified index to value. | ||
* | ||
* @param bitIndex a bit index | ||
* @return previous state of bitIndex that can be {@code 1} or {@code 0} | ||
* @throws IndexOutOfBoundsException if the specified index is negative | ||
*/ | ||
int set(int bitIndex, boolean value) { | ||
int wordIndex = wordIndex(bitIndex); | ||
long bitMask = 1L << bitIndex; | ||
int previous = (words[wordIndex] & bitMask) != 0 ? 1 : 0; | ||
if (value) { | ||
words[wordIndex] |= bitMask; | ||
} else { | ||
words[wordIndex] &= ~bitMask; | ||
} | ||
return previous; | ||
} | ||
|
||
int size() { | ||
return size; | ||
} | ||
} |
Oops, something went wrong.