Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
31b722f4
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
31b722f4
编写于
4月 11, 2013
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simple (not thread-safe) memoized functions supported
上级
af2f2637
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
157 addition
and
17 deletion
+157
-17
compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/storage/LockBasedStorageManager.java
...et/lang/resolve/lazy/storage/LockBasedStorageManager.java
+1
-17
compiler/util/src/org/jetbrains/jet/utils/NotNullMemoizedFunction.java
.../src/org/jetbrains/jet/utils/NotNullMemoizedFunction.java
+54
-0
compiler/util/src/org/jetbrains/jet/utils/NullableMemoizedFunction.java
...src/org/jetbrains/jet/utils/NullableMemoizedFunction.java
+65
-0
compiler/util/src/org/jetbrains/jet/utils/Nulls.java
compiler/util/src/org/jetbrains/jet/utils/Nulls.java
+37
-0
未找到文件。
compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/storage/LockBasedStorageManager.java
浏览文件 @
31b722f4
...
...
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import
org.jetbrains.jet.lang.resolve.BindingTrace
;
import
org.jetbrains.jet.util.slicedmap.ReadOnlySlice
;
import
org.jetbrains.jet.util.slicedmap.WritableSlice
;
import
org.jetbrains.jet.utils.Nulls
;
import
java.util.Collection
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -107,23 +108,6 @@ public class LockBasedStorageManager implements StorageManager {
return
new
LockProtectedTrace
(
lock
,
originalTrace
);
}
private
static
class
Nulls
{
private
static
final
Object
NULL_VALUE
=
new
Object
();
@Nullable
@SuppressWarnings
(
"unchecked"
)
private
static
<
V
>
V
unescape
(
@NotNull
Object
value
)
{
if
(
value
==
NULL_VALUE
)
return
null
;
return
(
V
)
value
;
}
@NotNull
private
static
<
V
>
Object
escape
(
@Nullable
V
value
)
{
if
(
value
==
null
)
return
NULL_VALUE
;
return
value
;
}
}
private
static
class
LockBasedLazyValue
<
T
>
implements
NullableLazyValue
<
T
>
{
private
final
Object
lock
;
private
final
Computable
<
T
>
computable
;
...
...
compiler/util/src/org/jetbrains/jet/utils/NotNullMemoizedFunction.java
0 → 100644
浏览文件 @
31b722f4
/*
* Copyright 2010-2013 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
org.jetbrains.jet.utils
;
import
com.intellij.util.NotNullFunction
;
import
org.jetbrains.annotations.NotNull
;
import
java.util.Map
;
public
abstract
class
NotNullMemoizedFunction
<
K
,
V
>
extends
NullableMemoizedFunction
<
K
,
V
>
implements
NotNullFunction
<
K
,
V
>
{
public
static
<
K
,
V
>
NotNullFunction
<
K
,
V
>
create
(
@NotNull
final
NotNullFunction
<
K
,
V
>
compute
)
{
return
new
NotNullMemoizedFunction
<
K
,
V
>()
{
@NotNull
@Override
protected
V
compute
(
@NotNull
K
input
)
{
return
compute
.
fun
(
input
);
}
};
}
public
NotNullMemoizedFunction
(
@NotNull
Map
<
K
,
Object
>
map
)
{
super
(
map
);
}
public
NotNullMemoizedFunction
()
{
super
();
}
@NotNull
@Override
public
V
fun
(
@NotNull
K
input
)
{
//noinspection ConstantConditions
return
super
.
fun
(
input
);
}
@NotNull
@Override
protected
abstract
V
compute
(
@NotNull
K
input
);
}
compiler/util/src/org/jetbrains/jet/utils/NullableMemoizedFunction.java
0 → 100644
浏览文件 @
31b722f4
/*
* Copyright 2010-2013 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
org.jetbrains.jet.utils
;
import
com.intellij.util.Function
;
import
com.intellij.util.NullableFunction
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
java.util.HashMap
;
import
java.util.Map
;
public
abstract
class
NullableMemoizedFunction
<
K
,
V
>
implements
NullableFunction
<
K
,
V
>
{
public
static
<
K
,
V
>
NullableFunction
<
K
,
V
>
create
(
@NotNull
final
Function
<
K
,
V
>
compute
)
{
return
new
NullableMemoizedFunction
<
K
,
V
>()
{
@Nullable
@Override
protected
V
compute
(
@NotNull
K
input
)
{
return
compute
.
fun
(
input
);
}
};
}
private
final
Map
<
K
,
Object
>
cache
;
public
NullableMemoizedFunction
(
@NotNull
Map
<
K
,
Object
>
map
)
{
this
.
cache
=
map
;
}
public
NullableMemoizedFunction
()
{
this
(
new
HashMap
<
K
,
Object
>());
}
@Override
@Nullable
public
V
fun
(
@NotNull
K
input
)
{
Object
value
=
cache
.
get
(
input
);
if
(
value
!=
null
)
return
Nulls
.
unescape
(
value
);
V
typedValue
=
compute
(
input
);
Object
oldValue
=
cache
.
put
(
input
,
Nulls
.
escape
(
typedValue
));
assert
oldValue
==
null
:
"Race condition detected"
;
return
typedValue
;
}
@Nullable
protected
abstract
V
compute
(
@NotNull
K
input
);
}
compiler/util/src/org/jetbrains/jet/utils/Nulls.java
0 → 100644
浏览文件 @
31b722f4
/*
* Copyright 2010-2013 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
org.jetbrains.jet.utils
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
public
class
Nulls
{
private
static
final
Object
NULL_VALUE
=
new
Object
();
@Nullable
@SuppressWarnings
(
"unchecked"
)
public
static
<
V
>
V
unescape
(
@NotNull
Object
value
)
{
if
(
value
==
NULL_VALUE
)
return
null
;
return
(
V
)
value
;
}
@NotNull
public
static
<
V
>
Object
escape
(
@Nullable
V
value
)
{
if
(
value
==
null
)
return
NULL_VALUE
;
return
value
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录