SegmentPool.smali

.class public final Lokio/SegmentPool;
.super Ljava/lang/Object;
.source "SegmentPool.kt"


# static fields
.field public static final INSTANCE:Lokio/SegmentPool;

.field public static final MAX_SIZE:J = 0x10000L

.field private static byteCount:J

.field private static next:Lokio/Segment;


# direct methods
.method static constructor <clinit>()V
    .registers 1

    .line 1
    new-instance v0, Lokio/SegmentPool;

    invoke-direct {v0}, Lokio/SegmentPool;-><init>()V

    sput-object v0, Lokio/SegmentPool;->INSTANCE:Lokio/SegmentPool;

    return-void
.end method

.method private constructor <init>()V
    .registers 1

    .line 1
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


# virtual methods
.method public final getByteCount()J
    .registers 3

    .line 1
    sget-wide v0, Lokio/SegmentPool;->byteCount:J

    return-wide v0
.end method

.method public final getNext()Lokio/Segment;
    .registers 2

    .line 1
    sget-object v0, Lokio/SegmentPool;->next:Lokio/Segment;

    return-object v0
.end method

.method public final recycle(Lokio/Segment;)V
    .registers 10

    const-string v0, "segment"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/i;->d(Ljava/lang/Object;Ljava/lang/String;)V

    .line 1
    iget-object v0, p1, Lokio/Segment;->next:Lokio/Segment;

    const/4 v1, 0x0

    if-nez v0, :cond_10

    iget-object v0, p1, Lokio/Segment;->prev:Lokio/Segment;

    if-nez v0, :cond_10

    const/4 v0, 0x1

    goto :goto_11

    :cond_10
    const/4 v0, 0x0

    :goto_11
    if-eqz v0, :cond_40

    .line 2
    iget-boolean v0, p1, Lokio/Segment;->shared:Z

    if-eqz v0, :cond_18

    return-void

    .line 3
    :cond_18
    monitor-enter p0

    .line 4
    :try_start_19
    sget-wide v2, Lokio/SegmentPool;->byteCount:J
    :try_end_1b
    .catchall {:try_start_19 .. :try_end_1b} :catchall_3d

    const/16 v0, 0x2000

    int-to-long v4, v0

    add-long/2addr v2, v4

    const-wide/32 v6, 0x10000

    cmp-long v0, v2, v6

    if-lez v0, :cond_28

    monitor-exit p0

    return-void

    .line 5
    :cond_28
    :try_start_28
    sget-wide v2, Lokio/SegmentPool;->byteCount:J

    add-long/2addr v2, v4

    sput-wide v2, Lokio/SegmentPool;->byteCount:J

    .line 6
    sget-object v0, Lokio/SegmentPool;->next:Lokio/Segment;

    iput-object v0, p1, Lokio/Segment;->next:Lokio/Segment;

    .line 7
    iput v1, p1, Lokio/Segment;->limit:I

    .line 8
    iget v0, p1, Lokio/Segment;->limit:I

    iput v0, p1, Lokio/Segment;->pos:I

    .line 9
    sput-object p1, Lokio/SegmentPool;->next:Lokio/Segment;

    .line 10
    sget-object p1, Lkotlin/n;->a:Lkotlin/n;
    :try_end_3b
    .catchall {:try_start_28 .. :try_end_3b} :catchall_3d

    monitor-exit p0

    return-void

    :catchall_3d
    move-exception p1

    monitor-exit p0

    throw p1

    .line 11
    :cond_40
    new-instance p1, Ljava/lang/IllegalArgumentException;

    const-string v0, "Failed requirement."

    invoke-direct {p1, v0}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw p1
.end method

.method public final setByteCount(J)V
    .registers 3

    .line 1
    sput-wide p1, Lokio/SegmentPool;->byteCount:J

    return-void
.end method

.method public final setNext(Lokio/Segment;)V
    .registers 2

    .line 1
    sput-object p1, Lokio/SegmentPool;->next:Lokio/Segment;

    return-void
.end method

.method public final take()Lokio/Segment;
    .registers 6

    .line 1
    monitor-enter p0

    .line 2
    :try_start_1
    sget-object v0, Lokio/SegmentPool;->next:Lokio/Segment;

    if-eqz v0, :cond_16

    .line 3
    iget-object v1, v0, Lokio/Segment;->next:Lokio/Segment;

    sput-object v1, Lokio/SegmentPool;->next:Lokio/Segment;

    const/4 v1, 0x0

    .line 4
    iput-object v1, v0, Lokio/Segment;->next:Lokio/Segment;

    .line 5
    sget-wide v1, Lokio/SegmentPool;->byteCount:J

    const/16 v3, 0x2000

    int-to-long v3, v3

    sub-long/2addr v1, v3

    sput-wide v1, Lokio/SegmentPool;->byteCount:J
    :try_end_14
    .catchall {:try_start_1 .. :try_end_14} :catchall_1d

    .line 6
    monitor-exit p0

    return-object v0

    .line 7
    :cond_16
    monitor-exit p0

    .line 8
    new-instance v0, Lokio/Segment;

    invoke-direct {v0}, Lokio/Segment;-><init>()V

    return-object v0

    :catchall_1d
    move-exception v0

    .line 9
    monitor-exit p0

    throw v0
.end method