Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
f7a939ec
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f7a939ec
编写于
10月 22, 2017
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid some unnecessary object allocations initializing Glide.
上级
90f1cc93
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
35 deletion
+90
-35
library/src/main/java/com/bumptech/glide/Glide.java
library/src/main/java/com/bumptech/glide/Glide.java
+58
-33
library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java
...in/java/com/bumptech/glide/load/model/ResourceLoader.java
+1
-1
library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java
...n/java/com/bumptech/glide/load/model/UnitModelLoader.java
+31
-1
未找到文件。
library/src/main/java/com/bumptech/glide/Glide.java
浏览文件 @
f7a939ec
...
@@ -300,43 +300,66 @@ public class Glide implements ComponentCallbacks2 {
...
@@ -300,43 +300,66 @@ public class Glide implements ComponentCallbacks2 {
resources
.
getDisplayMetrics
(),
bitmapPool
,
arrayPool
);
resources
.
getDisplayMetrics
(),
bitmapPool
,
arrayPool
);
ByteBufferGifDecoder
byteBufferGifDecoder
=
ByteBufferGifDecoder
byteBufferGifDecoder
=
new
ByteBufferGifDecoder
(
context
,
registry
.
getImageHeaderParsers
(),
bitmapPool
,
arrayPool
);
new
ByteBufferGifDecoder
(
context
,
registry
.
getImageHeaderParsers
(),
bitmapPool
,
arrayPool
);
VideoBitmapDecoder
videoBitmapDecoder
=
new
VideoBitmapDecoder
(
bitmapPool
);
ByteBufferBitmapDecoder
byteBufferBitmapDecoder
=
new
ByteBufferBitmapDecoder
(
downsampler
);
StreamBitmapDecoder
streamBitmapDecoder
=
new
StreamBitmapDecoder
(
downsampler
,
arrayPool
);
ResourceDrawableDecoder
resourceDrawableDecoder
=
new
ResourceDrawableDecoder
(
context
,
bitmapPool
);
ResourceLoader
.
StreamFactory
resourceLoaderStreamFactory
=
new
ResourceLoader
.
StreamFactory
(
resources
);
ResourceLoader
.
UriFactory
resourceLoaderUriFactory
=
new
ResourceLoader
.
UriFactory
(
resources
);
ResourceLoader
.
FileDescriptorFactory
resourceLoaderFileDescriptorFactory
=
new
ResourceLoader
.
FileDescriptorFactory
(
resources
);
BitmapEncoder
bitmapEncoder
=
new
BitmapEncoder
();
registry
registry
.
append
(
ByteBuffer
.
class
,
new
ByteBufferEncoder
())
.
append
(
ByteBuffer
.
class
,
new
ByteBufferEncoder
())
.
append
(
InputStream
.
class
,
new
StreamEncoder
(
arrayPool
))
.
append
(
InputStream
.
class
,
new
StreamEncoder
(
arrayPool
))
/* Bitmaps */
/* Bitmaps */
.
append
(
Registry
.
BUCKET_BITMAP
,
ByteBuffer
.
class
,
Bitmap
.
class
,
.
append
(
Registry
.
BUCKET_BITMAP
,
ByteBuffer
.
class
,
Bitmap
.
class
,
byteBufferBitmapDecoder
)
new
ByteBufferBitmapDecoder
(
downsampler
))
.
append
(
Registry
.
BUCKET_BITMAP
,
InputStream
.
class
,
Bitmap
.
class
,
streamBitmapDecoder
)
.
append
(
Registry
.
BUCKET_BITMAP
,
InputStream
.
class
,
Bitmap
.
class
,
.
append
(
new
StreamBitmapDecoder
(
downsampler
,
arrayPool
))
Registry
.
BUCKET_BITMAP
,
ParcelFileDescriptor
.
class
,
Bitmap
.
class
,
videoBitmapDecoder
)
.
append
(
Registry
.
BUCKET_BITMAP
,
ParcelFileDescriptor
.
class
,
Bitmap
.
class
,
.
append
(
Bitmap
.
class
,
bitmapEncoder
)
new
VideoBitmapDecoder
(
bitmapPool
))
/* BitmapDrawables */
.
append
(
Bitmap
.
class
,
new
BitmapEncoder
())
.
append
(
/* GlideBitmapDrawables */
Registry
.
BUCKET_BITMAP_DRAWABLE
,
.
append
(
Registry
.
BUCKET_BITMAP_DRAWABLE
,
ByteBuffer
.
class
,
BitmapDrawable
.
class
,
ByteBuffer
.
class
,
new
BitmapDrawableDecoder
<>(
resources
,
bitmapPool
,
BitmapDrawable
.
class
,
new
ByteBufferBitmapDecoder
(
downsampler
)))
new
BitmapDrawableDecoder
<>(
resources
,
bitmapPool
,
byteBufferBitmapDecoder
))
.
append
(
Registry
.
BUCKET_BITMAP_DRAWABLE
,
InputStream
.
class
,
BitmapDrawable
.
class
,
.
append
(
new
BitmapDrawableDecoder
<>(
resources
,
bitmapPool
,
Registry
.
BUCKET_BITMAP_DRAWABLE
,
new
StreamBitmapDecoder
(
downsampler
,
arrayPool
)))
InputStream
.
class
,
.
append
(
Registry
.
BUCKET_BITMAP_DRAWABLE
,
ParcelFileDescriptor
.
class
,
BitmapDrawable
.
class
,
BitmapDrawable
.
class
,
new
BitmapDrawableDecoder
<>(
resources
,
bitmapPool
,
new
VideoBitmapDecoder
(
bitmapPool
)))
new
BitmapDrawableDecoder
<>(
resources
,
bitmapPool
,
streamBitmapDecoder
))
.
append
(
BitmapDrawable
.
class
,
new
BitmapDrawableEncoder
(
bitmapPool
,
new
BitmapEncoder
()))
.
append
(
Registry
.
BUCKET_BITMAP_DRAWABLE
,
ParcelFileDescriptor
.
class
,
BitmapDrawable
.
class
,
new
BitmapDrawableDecoder
<>(
resources
,
bitmapPool
,
videoBitmapDecoder
))
.
append
(
BitmapDrawable
.
class
,
new
BitmapDrawableEncoder
(
bitmapPool
,
bitmapEncoder
))
/* GIFs */
/* GIFs */
.
append
(
Registry
.
BUCKET_GIF
,
InputStream
.
class
,
GifDrawable
.
class
,
.
append
(
Registry
.
BUCKET_GIF
,
InputStream
.
class
,
GifDrawable
.
class
,
new
StreamGifDecoder
(
registry
.
getImageHeaderParsers
(),
byteBufferGifDecoder
,
arrayPool
))
new
StreamGifDecoder
(
registry
.
getImageHeaderParsers
(),
byteBufferGifDecoder
,
arrayPool
))
.
append
(
Registry
.
BUCKET_GIF
,
ByteBuffer
.
class
,
GifDrawable
.
class
,
byteBufferGifDecoder
)
.
append
(
Registry
.
BUCKET_GIF
,
ByteBuffer
.
class
,
GifDrawable
.
class
,
byteBufferGifDecoder
)
.
append
(
GifDrawable
.
class
,
new
GifDrawableEncoder
())
.
append
(
GifDrawable
.
class
,
new
GifDrawableEncoder
())
/* GIF Frames */
/* GIF Frames */
// Compilation with Gradle requires the type to be specified for UnitModelLoader here.
// Compilation with Gradle requires the type to be specified for UnitModelLoader here.
.
append
(
GifDecoder
.
class
,
GifDecoder
.
class
,
new
UnitModelLoader
.
Factory
<
GifDecoder
>())
.
append
(
.
append
(
Registry
.
BUCKET_BITMAP
,
GifDecoder
.
class
,
Bitmap
.
class
,
GifDecoder
.
class
,
GifDecoder
.
class
,
UnitModelLoader
.
Factory
.<
GifDecoder
>
getInstance
())
.
append
(
Registry
.
BUCKET_BITMAP
,
GifDecoder
.
class
,
Bitmap
.
class
,
new
GifFrameResourceDecoder
(
bitmapPool
))
new
GifFrameResourceDecoder
(
bitmapPool
))
/* Drawables */
/* Drawables */
.
append
(
Uri
.
class
,
Drawable
.
class
,
new
ResourceDrawableDecoder
(
context
,
bitmapPool
))
.
append
(
Uri
.
class
,
Drawable
.
class
,
resourceDrawableDecoder
)
.
append
(
Uri
.
class
,
Bitmap
.
class
,
.
append
(
new
ResourceBitmapDecoder
(
Uri
.
class
,
Bitmap
.
class
,
new
ResourceBitmapDecoder
(
resourceDrawableDecoder
,
bitmapPool
))
new
ResourceDrawableDecoder
(
context
,
bitmapPool
),
bitmapPool
))
/* Files */
/* Files */
.
register
(
new
ByteBufferRewinder
.
Factory
())
.
register
(
new
ByteBufferRewinder
.
Factory
())
.
append
(
File
.
class
,
ByteBuffer
.
class
,
new
ByteBufferFileLoader
.
Factory
())
.
append
(
File
.
class
,
ByteBuffer
.
class
,
new
ByteBufferFileLoader
.
Factory
())
...
@@ -344,21 +367,21 @@ public class Glide implements ComponentCallbacks2 {
...
@@ -344,21 +367,21 @@ public class Glide implements ComponentCallbacks2 {
.
append
(
File
.
class
,
File
.
class
,
new
FileDecoder
())
.
append
(
File
.
class
,
File
.
class
,
new
FileDecoder
())
.
append
(
File
.
class
,
ParcelFileDescriptor
.
class
,
new
FileLoader
.
FileDescriptorFactory
())
.
append
(
File
.
class
,
ParcelFileDescriptor
.
class
,
new
FileLoader
.
FileDescriptorFactory
())
// Compilation with Gradle requires the type to be specified for UnitModelLoader here.
// Compilation with Gradle requires the type to be specified for UnitModelLoader here.
.
append
(
File
.
class
,
File
.
class
,
new
UnitModelLoader
.
Factory
<
File
>
())
.
append
(
File
.
class
,
File
.
class
,
UnitModelLoader
.
Factory
.<
File
>
getInstance
())
/* Models */
/* Models */
.
register
(
new
InputStreamRewinder
.
Factory
(
arrayPool
))
.
register
(
new
InputStreamRewinder
.
Factory
(
arrayPool
))
.
append
(
int
.
class
,
InputStream
.
class
,
new
ResourceLoader
.
StreamFactory
(
resources
)
)
.
append
(
int
.
class
,
InputStream
.
class
,
resourceLoaderStreamFactory
)
.
append
(
.
append
(
int
.
class
,
int
.
class
,
ParcelFileDescriptor
.
class
,
ParcelFileDescriptor
.
class
,
new
ResourceLoader
.
FileDescriptorFactory
(
resources
)
)
resourceLoaderFileDescriptorFactory
)
.
append
(
Integer
.
class
,
InputStream
.
class
,
new
ResourceLoader
.
StreamFactory
(
resources
)
)
.
append
(
Integer
.
class
,
InputStream
.
class
,
resourceLoaderStreamFactory
)
.
append
(
.
append
(
Integer
.
class
,
Integer
.
class
,
ParcelFileDescriptor
.
class
,
ParcelFileDescriptor
.
class
,
new
ResourceLoader
.
FileDescriptorFactory
(
resources
)
)
resourceLoaderFileDescriptorFactory
)
.
append
(
Integer
.
class
,
Uri
.
class
,
new
ResourceLoader
.
UriFactory
(
resources
)
)
.
append
(
Integer
.
class
,
Uri
.
class
,
resourceLoaderUriFactory
)
.
append
(
int
.
class
,
Uri
.
class
,
new
ResourceLoader
.
UriFactory
(
resources
)
)
.
append
(
int
.
class
,
Uri
.
class
,
resourceLoaderUriFactory
)
.
append
(
String
.
class
,
InputStream
.
class
,
new
DataUrlLoader
.
StreamFactory
())
.
append
(
String
.
class
,
InputStream
.
class
,
new
DataUrlLoader
.
StreamFactory
())
.
append
(
String
.
class
,
InputStream
.
class
,
new
StringLoader
.
StreamFactory
())
.
append
(
String
.
class
,
InputStream
.
class
,
new
StringLoader
.
StreamFactory
())
.
append
(
String
.
class
,
ParcelFileDescriptor
.
class
,
new
StringLoader
.
FileDescriptorFactory
())
.
append
(
String
.
class
,
ParcelFileDescriptor
.
class
,
new
StringLoader
.
FileDescriptorFactory
())
...
@@ -382,9 +405,11 @@ public class Glide implements ComponentCallbacks2 {
...
@@ -382,9 +405,11 @@ public class Glide implements ComponentCallbacks2 {
.
append
(
GlideUrl
.
class
,
InputStream
.
class
,
new
HttpGlideUrlLoader
.
Factory
())
.
append
(
GlideUrl
.
class
,
InputStream
.
class
,
new
HttpGlideUrlLoader
.
Factory
())
.
append
(
byte
[].
class
,
ByteBuffer
.
class
,
new
ByteArrayLoader
.
ByteBufferFactory
())
.
append
(
byte
[].
class
,
ByteBuffer
.
class
,
new
ByteArrayLoader
.
ByteBufferFactory
())
.
append
(
byte
[].
class
,
InputStream
.
class
,
new
ByteArrayLoader
.
StreamFactory
())
.
append
(
byte
[].
class
,
InputStream
.
class
,
new
ByteArrayLoader
.
StreamFactory
())
.
append
(
Uri
.
class
,
Uri
.
class
,
new
UnitModelLoader
.
Factory
<
Uri
>
())
.
append
(
Uri
.
class
,
Uri
.
class
,
UnitModelLoader
.
Factory
.<
Uri
>
getInstance
())
/* Transcoders */
/* Transcoders */
.
register
(
Bitmap
.
class
,
BitmapDrawable
.
class
,
.
register
(
Bitmap
.
class
,
BitmapDrawable
.
class
,
new
BitmapDrawableTranscoder
(
resources
,
bitmapPool
))
new
BitmapDrawableTranscoder
(
resources
,
bitmapPool
))
.
register
(
Bitmap
.
class
,
byte
[].
class
,
new
BitmapBytesTranscoder
())
.
register
(
Bitmap
.
class
,
byte
[].
class
,
new
BitmapBytesTranscoder
())
.
register
(
GifDrawable
.
class
,
byte
[].
class
,
new
GifDrawableBytesTranscoder
());
.
register
(
GifDrawable
.
class
,
byte
[].
class
,
new
GifDrawableBytesTranscoder
());
...
...
library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java
浏览文件 @
f7a939ec
...
@@ -111,7 +111,7 @@ public class ResourceLoader<Data> implements ModelLoader<Integer, Data> {
...
@@ -111,7 +111,7 @@ public class ResourceLoader<Data> implements ModelLoader<Integer, Data> {
@Override
@Override
public
ModelLoader
<
Integer
,
Uri
>
build
(
MultiModelLoaderFactory
multiFactory
)
{
public
ModelLoader
<
Integer
,
Uri
>
build
(
MultiModelLoaderFactory
multiFactory
)
{
return
new
ResourceLoader
<>(
resources
,
new
UnitModelLoader
<
Uri
>
());
return
new
ResourceLoader
<>(
resources
,
UnitModelLoader
.<
Uri
>
getInstance
());
}
}
@Override
@Override
...
...
library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java
浏览文件 @
f7a939ec
...
@@ -14,6 +14,21 @@ import com.bumptech.glide.signature.ObjectKey;
...
@@ -14,6 +14,21 @@ import com.bumptech.glide.signature.ObjectKey;
* @param <Model> The type of model that will also be returned as decodable data.
* @param <Model> The type of model that will also be returned as decodable data.
*/
*/
public
class
UnitModelLoader
<
Model
>
implements
ModelLoader
<
Model
,
Model
>
{
public
class
UnitModelLoader
<
Model
>
implements
ModelLoader
<
Model
,
Model
>
{
@SuppressWarnings
(
"deprecation"
)
private
static
final
UnitModelLoader
<?>
INSTANCE
=
new
UnitModelLoader
<>();
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
UnitModelLoader
<
T
>
getInstance
()
{
return
(
UnitModelLoader
<
T
>)
INSTANCE
;
}
/**
* @deprecated Use {@link #getInstance()} instead.
*/
@Deprecated
public
UnitModelLoader
()
{
// Intentionally empty.
}
@Override
@Override
public
LoadData
<
Model
>
buildLoadData
(
Model
model
,
int
width
,
int
height
,
public
LoadData
<
Model
>
buildLoadData
(
Model
model
,
int
width
,
int
height
,
...
@@ -68,11 +83,26 @@ public class UnitModelLoader<Model> implements ModelLoader<Model, Model> {
...
@@ -68,11 +83,26 @@ public class UnitModelLoader<Model> implements ModelLoader<Model, Model> {
*
*
* @param <Model> The type of model that will also be returned as decodable data.
* @param <Model> The type of model that will also be returned as decodable data.
*/
*/
// PMD seems to be just wrong here, maybe confused by getInstance in UnitModelLoader.
@SuppressWarnings
(
"PMD.SingleMethodSingleton"
)
public
static
class
Factory
<
Model
>
implements
ModelLoaderFactory
<
Model
,
Model
>
{
public
static
class
Factory
<
Model
>
implements
ModelLoaderFactory
<
Model
,
Model
>
{
@SuppressWarnings
(
"deprecation"
)
private
static
final
Factory
<?>
FACTORY
=
new
Factory
<>();
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
Factory
<
T
>
getInstance
()
{
return
(
Factory
<
T
>)
FACTORY
;
}
/** @deprecated Use {@link #getInstance()} instead. */
@Deprecated
public
Factory
()
{
// Intentionally empty.
}
@Override
@Override
public
ModelLoader
<
Model
,
Model
>
build
(
MultiModelLoaderFactory
multiFactory
)
{
public
ModelLoader
<
Model
,
Model
>
build
(
MultiModelLoaderFactory
multiFactory
)
{
return
new
UnitModelLoader
<>
();
return
UnitModelLoader
.
getInstance
();
}
}
@Override
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录