IndexedRingBuffer.smali
.class public final Lrx/internal/util/IndexedRingBuffer;
.super Ljava/lang/Object;
.source "IndexedRingBuffer.java"
# interfaces
.implements Lrx/Subscription;
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lrx/internal/util/IndexedRingBuffer$IndexSection;,
Lrx/internal/util/IndexedRingBuffer$ElementSection;
}
.end annotation
.annotation system Ldalvik/annotation/Signature;
value = {
"<E:",
"Ljava/lang/Object;",
">",
"Ljava/lang/Object;",
"Lrx/Subscription;"
}
.end annotation
# static fields
.field static final SIZE:I
# instance fields
.field private final elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
.annotation system Ldalvik/annotation/Signature;
value = {
"Lrx/internal/util/IndexedRingBuffer$ElementSection<",
"TE;>;"
}
.end annotation
.end field
.field final index:Ljava/util/concurrent/atomic/AtomicInteger;
.field private final removed:Lrx/internal/util/IndexedRingBuffer$IndexSection;
.field final removedIndex:Ljava/util/concurrent/atomic/AtomicInteger;
# direct methods
.method static constructor <clinit>()V
.registers 6
.line 1
invoke-static {}, Lrx/internal/util/PlatformDependent;->isAndroid()Z
move-result v0
if-eqz v0, :cond_9
const/16 v0, 0x8
goto :goto_b
:cond_9
const/16 v0, 0x80
:goto_b
const-string v1, "rx.indexed-ring-buffer.size"
.line 2
invoke-static {v1}, Ljava/lang/System;->getProperty(Ljava/lang/String;)Ljava/lang/String;
move-result-object v1
if-eqz v1, :cond_3b
.line 3
:try_start_13
invoke-static {v1}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I
move-result v0
:try_end_17
.catch Ljava/lang/NumberFormatException; {:try_start_13 .. :try_end_17} :catch_18
goto :goto_3b
:catch_18
move-exception v2
.line 4
sget-object v3, Ljava/lang/System;->err:Ljava/io/PrintStream;
new-instance v4, Ljava/lang/StringBuilder;
invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V
const-string v5, "Failed to set \'rx.indexed-ring-buffer.size\' with value "
invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
const-string v1, " => "
invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v2}, Ljava/lang/NumberFormatException;->getMessage()Ljava/lang/String;
move-result-object v1
invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v1
invoke-virtual {v3, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
.line 5
:cond_3b
:goto_3b
sput v0, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
return-void
.end method
.method constructor <init>()V
.registers 2
.line 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 2
new-instance v0, Lrx/internal/util/IndexedRingBuffer$ElementSection;
invoke-direct {v0}, Lrx/internal/util/IndexedRingBuffer$ElementSection;-><init>()V
iput-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
.line 3
new-instance v0, Lrx/internal/util/IndexedRingBuffer$IndexSection;
invoke-direct {v0}, Lrx/internal/util/IndexedRingBuffer$IndexSection;-><init>()V
iput-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->removed:Lrx/internal/util/IndexedRingBuffer$IndexSection;
.line 4
new-instance v0, Ljava/util/concurrent/atomic/AtomicInteger;
invoke-direct {v0}, Ljava/util/concurrent/atomic/AtomicInteger;-><init>()V
iput-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
.line 5
new-instance v0, Ljava/util/concurrent/atomic/AtomicInteger;
invoke-direct {v0}, Ljava/util/concurrent/atomic/AtomicInteger;-><init>()V
iput-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->removedIndex:Ljava/util/concurrent/atomic/AtomicInteger;
return-void
.end method
.method private forEach(Lrx/functions/Func1;II)I
.registers 9
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Lrx/functions/Func1<",
"-TE;",
"Ljava/lang/Boolean;",
">;II)I"
}
.end annotation
.line 6
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result v0
.line 7
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
.line 8
sget v2, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-lt p2, v2, :cond_18
.line 9
invoke-direct {p0, p2}, Lrx/internal/util/IndexedRingBuffer;->getElementSection(I)Lrx/internal/util/IndexedRingBuffer$ElementSection;
move-result-object v1
.line 10
sget v2, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
rem-int v2, p2, v2
move v4, v2
move v2, p2
move p2, v4
goto :goto_19
:cond_18
move v2, p2
:goto_19
if-eqz v1, :cond_4a
.line 11
:goto_1b
sget v3, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-ge p2, v3, :cond_3f
if-ge v2, v0, :cond_4a
if-lt v2, p3, :cond_24
goto :goto_4a
.line 12
:cond_24
iget-object v3, v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;->array:Ljava/util/concurrent/atomic/AtomicReferenceArray;
invoke-virtual {v3, p2}, Ljava/util/concurrent/atomic/AtomicReferenceArray;->get(I)Ljava/lang/Object;
move-result-object v3
if-nez v3, :cond_2d
goto :goto_3a
.line 13
:cond_2d
invoke-interface {p1, v3}, Lrx/functions/Func1;->call(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v3
check-cast v3, Ljava/lang/Boolean;
invoke-virtual {v3}, Ljava/lang/Boolean;->booleanValue()Z
move-result v3
if-nez v3, :cond_3a
return v2
:cond_3a
:goto_3a
add-int/lit8 p2, p2, 0x1
add-int/lit8 v2, v2, 0x1
goto :goto_1b
.line 14
:cond_3f
iget-object p2, v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;->next:Ljava/util/concurrent/atomic/AtomicReference;
invoke-virtual {p2}, Ljava/util/concurrent/atomic/AtomicReference;->get()Ljava/lang/Object;
move-result-object p2
move-object v1, p2
check-cast v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;
const/4 p2, 0x0
goto :goto_19
:cond_4a
:goto_4a
return v2
.end method
.method private getElementSection(I)Lrx/internal/util/IndexedRingBuffer$ElementSection;
.registers 4
.annotation system Ldalvik/annotation/Signature;
value = {
"(I)",
"Lrx/internal/util/IndexedRingBuffer$ElementSection<",
"TE;>;"
}
.end annotation
.line 1
sget v0, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-ge p1, v0, :cond_7
.line 2
iget-object p1, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
return-object p1
.line 3
:cond_7
div-int/2addr p1, v0
.line 4
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
const/4 v1, 0x0
:goto_b
if-ge v1, p1, :cond_14
.line 5
invoke-virtual {v0}, Lrx/internal/util/IndexedRingBuffer$ElementSection;->getNext()Lrx/internal/util/IndexedRingBuffer$ElementSection;
move-result-object v0
add-int/lit8 v1, v1, 0x1
goto :goto_b
:cond_14
return-object v0
.end method
.method private declared-synchronized getIndexForAdd()I
.registers 4
monitor-enter p0
.line 1
:try_start_1
invoke-direct {p0}, Lrx/internal/util/IndexedRingBuffer;->getIndexFromPreviouslyRemoved()I
move-result v0
if-ltz v0, :cond_2d
.line 2
sget v1, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
const/4 v2, -0x1
if-ge v0, v1, :cond_13
.line 3
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->removed:Lrx/internal/util/IndexedRingBuffer$IndexSection;
invoke-virtual {v1, v0, v2}, Lrx/internal/util/IndexedRingBuffer$IndexSection;->getAndSet(II)I
move-result v0
goto :goto_1f
.line 4
:cond_13
sget v1, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
rem-int v1, v0, v1
.line 5
invoke-direct {p0, v0}, Lrx/internal/util/IndexedRingBuffer;->getIndexSection(I)Lrx/internal/util/IndexedRingBuffer$IndexSection;
move-result-object v0
invoke-virtual {v0, v1, v2}, Lrx/internal/util/IndexedRingBuffer$IndexSection;->getAndSet(II)I
move-result v0
.line 6
:goto_1f
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v1}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result v1
if-ne v0, v1, :cond_33
.line 7
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v1}, Ljava/util/concurrent/atomic/AtomicInteger;->getAndIncrement()I
goto :goto_33
.line 8
:cond_2d
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicInteger;->getAndIncrement()I
move-result v0
:try_end_33
.catchall {:try_start_1 .. :try_end_33} :catchall_35
.line 9
:cond_33
:goto_33
monitor-exit p0
return v0
:catchall_35
move-exception v0
monitor-exit p0
throw v0
.end method
.method private declared-synchronized getIndexFromPreviouslyRemoved()I
.registers 4
monitor-enter p0
.line 1
:cond_1
:try_start_1
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->removedIndex:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result v0
if-lez v0, :cond_15
.line 2
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->removedIndex:Ljava/util/concurrent/atomic/AtomicInteger;
add-int/lit8 v2, v0, -0x1
invoke-virtual {v1, v0, v2}, Ljava/util/concurrent/atomic/AtomicInteger;->compareAndSet(II)Z
move-result v0
:try_end_11
.catchall {:try_start_1 .. :try_end_11} :catchall_18
if-eqz v0, :cond_1
.line 3
monitor-exit p0
return v2
:cond_15
const/4 v0, -0x1
.line 4
monitor-exit p0
return v0
:catchall_18
move-exception v0
monitor-exit p0
goto :goto_1c
:goto_1b
throw v0
:goto_1c
goto :goto_1b
.end method
.method private getIndexSection(I)Lrx/internal/util/IndexedRingBuffer$IndexSection;
.registers 4
.line 1
sget v0, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-ge p1, v0, :cond_7
.line 2
iget-object p1, p0, Lrx/internal/util/IndexedRingBuffer;->removed:Lrx/internal/util/IndexedRingBuffer$IndexSection;
return-object p1
.line 3
:cond_7
div-int/2addr p1, v0
.line 4
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->removed:Lrx/internal/util/IndexedRingBuffer$IndexSection;
const/4 v1, 0x0
:goto_b
if-ge v1, p1, :cond_14
.line 5
invoke-virtual {v0}, Lrx/internal/util/IndexedRingBuffer$IndexSection;->getNext()Lrx/internal/util/IndexedRingBuffer$IndexSection;
move-result-object v0
add-int/lit8 v1, v1, 0x1
goto :goto_b
:cond_14
return-object v0
.end method
.method public static getInstance()Lrx/internal/util/IndexedRingBuffer;
.registers 1
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">()",
"Lrx/internal/util/IndexedRingBuffer<",
"TT;>;"
}
.end annotation
.line 1
new-instance v0, Lrx/internal/util/IndexedRingBuffer;
invoke-direct {v0}, Lrx/internal/util/IndexedRingBuffer;-><init>()V
return-object v0
.end method
.method private declared-synchronized pushRemovedIndex(I)V
.registers 4
monitor-enter p0
.line 1
:try_start_1
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->removedIndex:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicInteger;->getAndIncrement()I
move-result v0
.line 2
sget v1, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-ge v0, v1, :cond_11
.line 3
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->removed:Lrx/internal/util/IndexedRingBuffer$IndexSection;
invoke-virtual {v1, v0, p1}, Lrx/internal/util/IndexedRingBuffer$IndexSection;->set(II)V
goto :goto_1c
.line 4
:cond_11
sget v1, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
rem-int v1, v0, v1
.line 5
invoke-direct {p0, v0}, Lrx/internal/util/IndexedRingBuffer;->getIndexSection(I)Lrx/internal/util/IndexedRingBuffer$IndexSection;
move-result-object v0
invoke-virtual {v0, v1, p1}, Lrx/internal/util/IndexedRingBuffer$IndexSection;->set(II)V
:try_end_1c
.catchall {:try_start_1 .. :try_end_1c} :catchall_1e
.line 6
:goto_1c
monitor-exit p0
return-void
:catchall_1e
move-exception p1
monitor-exit p0
throw p1
.end method
# virtual methods
.method public add(Ljava/lang/Object;)I
.registers 5
.annotation system Ldalvik/annotation/Signature;
value = {
"(TE;)I"
}
.end annotation
.line 1
invoke-direct {p0}, Lrx/internal/util/IndexedRingBuffer;->getIndexForAdd()I
move-result v0
.line 2
sget v1, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-ge v0, v1, :cond_10
.line 3
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
iget-object v1, v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;->array:Ljava/util/concurrent/atomic/AtomicReferenceArray;
invoke-virtual {v1, v0, p1}, Ljava/util/concurrent/atomic/AtomicReferenceArray;->set(ILjava/lang/Object;)V
return v0
.line 4
:cond_10
rem-int v1, v0, v1
.line 5
invoke-direct {p0, v0}, Lrx/internal/util/IndexedRingBuffer;->getElementSection(I)Lrx/internal/util/IndexedRingBuffer$ElementSection;
move-result-object v2
iget-object v2, v2, Lrx/internal/util/IndexedRingBuffer$ElementSection;->array:Ljava/util/concurrent/atomic/AtomicReferenceArray;
invoke-virtual {v2, v1, p1}, Ljava/util/concurrent/atomic/AtomicReferenceArray;->set(ILjava/lang/Object;)V
return v0
.end method
.method public forEach(Lrx/functions/Func1;)I
.registers 3
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Lrx/functions/Func1<",
"-TE;",
"Ljava/lang/Boolean;",
">;)I"
}
.end annotation
const/4 v0, 0x0
.line 1
invoke-virtual {p0, p1, v0}, Lrx/internal/util/IndexedRingBuffer;->forEach(Lrx/functions/Func1;I)I
move-result p1
return p1
.end method
.method public forEach(Lrx/functions/Func1;I)I
.registers 6
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Lrx/functions/Func1<",
"-TE;",
"Ljava/lang/Boolean;",
">;I)I"
}
.end annotation
.line 2
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result v0
invoke-direct {p0, p1, p2, v0}, Lrx/internal/util/IndexedRingBuffer;->forEach(Lrx/functions/Func1;II)I
move-result v0
const/4 v1, 0x0
if-lez p2, :cond_1a
.line 3
iget-object v2, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v2}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result v2
if-ne v0, v2, :cond_1a
.line 4
invoke-direct {p0, p1, v1, p2}, Lrx/internal/util/IndexedRingBuffer;->forEach(Lrx/functions/Func1;II)I
move-result v0
goto :goto_23
.line 5
:cond_1a
iget-object p1, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {p1}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result p1
if-ne v0, p1, :cond_23
const/4 v0, 0x0
:cond_23
:goto_23
return v0
.end method
.method public isUnsubscribed()Z
.registers 2
const/4 v0, 0x0
return v0
.end method
.method public releaseToPool()V
.registers 8
.line 1
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicInteger;->get()I
move-result v0
.line 2
iget-object v1, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
const/4 v2, 0x0
const/4 v3, 0x0
:goto_a
if-eqz v1, :cond_2a
move v4, v3
const/4 v3, 0x0
.line 3
:goto_e
sget v5, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
if-ge v3, v5, :cond_20
if-lt v4, v0, :cond_15
goto :goto_2a
.line 4
:cond_15
iget-object v5, v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;->array:Ljava/util/concurrent/atomic/AtomicReferenceArray;
const/4 v6, 0x0
invoke-virtual {v5, v3, v6}, Ljava/util/concurrent/atomic/AtomicReferenceArray;->set(ILjava/lang/Object;)V
add-int/lit8 v3, v3, 0x1
add-int/lit8 v4, v4, 0x1
goto :goto_e
.line 5
:cond_20
iget-object v1, v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;->next:Ljava/util/concurrent/atomic/AtomicReference;
invoke-virtual {v1}, Ljava/util/concurrent/atomic/AtomicReference;->get()Ljava/lang/Object;
move-result-object v1
check-cast v1, Lrx/internal/util/IndexedRingBuffer$ElementSection;
move v3, v4
goto :goto_a
.line 6
:cond_2a
:goto_2a
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->index:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0, v2}, Ljava/util/concurrent/atomic/AtomicInteger;->set(I)V
.line 7
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->removedIndex:Ljava/util/concurrent/atomic/AtomicInteger;
invoke-virtual {v0, v2}, Ljava/util/concurrent/atomic/AtomicInteger;->set(I)V
return-void
.end method
.method public remove(I)Ljava/lang/Object;
.registers 5
.annotation system Ldalvik/annotation/Signature;
value = {
"(I)TE;"
}
.end annotation
.line 1
sget v0, Lrx/internal/util/IndexedRingBuffer;->SIZE:I
const/4 v1, 0x0
if-ge p1, v0, :cond_e
.line 2
iget-object v0, p0, Lrx/internal/util/IndexedRingBuffer;->elements:Lrx/internal/util/IndexedRingBuffer$ElementSection;
iget-object v0, v0, Lrx/internal/util/IndexedRingBuffer$ElementSection;->array:Ljava/util/concurrent/atomic/AtomicReferenceArray;
invoke-virtual {v0, p1, v1}, Ljava/util/concurrent/atomic/AtomicReferenceArray;->getAndSet(ILjava/lang/Object;)Ljava/lang/Object;
move-result-object v0
goto :goto_1a
.line 3
:cond_e
rem-int v0, p1, v0
.line 4
invoke-direct {p0, p1}, Lrx/internal/util/IndexedRingBuffer;->getElementSection(I)Lrx/internal/util/IndexedRingBuffer$ElementSection;
move-result-object v2
iget-object v2, v2, Lrx/internal/util/IndexedRingBuffer$ElementSection;->array:Ljava/util/concurrent/atomic/AtomicReferenceArray;
invoke-virtual {v2, v0, v1}, Ljava/util/concurrent/atomic/AtomicReferenceArray;->getAndSet(ILjava/lang/Object;)Ljava/lang/Object;
move-result-object v0
.line 5
:goto_1a
invoke-direct {p0, p1}, Lrx/internal/util/IndexedRingBuffer;->pushRemovedIndex(I)V
return-object v0
.end method
.method public unsubscribe()V
.registers 1
.line 1
invoke-virtual {p0}, Lrx/internal/util/IndexedRingBuffer;->releaseToPool()V
return-void
.end method