Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
qemu
提交
9970bd88
Q
qemu
项目概览
openeuler
/
qemu
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
qemu
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9970bd88
编写于
2月 03, 2012
作者:
P
Paolo Bonzini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
qom: avoid useless conversions from string to type
Signed-off-by:
N
Paolo Bonzini
<
pbonzini@redhat.com
>
上级
acc4af3f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
15 deletion
+12
-15
qom/object.c
qom/object.c
+12
-15
未找到文件。
qom/object.c
浏览文件 @
9970bd88
...
...
@@ -63,6 +63,8 @@ typedef struct Interface
#define INTERFACE(obj) OBJECT_CHECK(Interface, obj, TYPE_INTERFACE)
static
Type
type_interface
;
static
GHashTable
*
type_table_get
(
void
)
{
static
GHashTable
*
type_table
;
...
...
@@ -384,25 +386,20 @@ static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
return
false
;
}
static
bool
object_is_type
(
Object
*
obj
,
const
char
*
typenam
e
)
static
bool
object_is_type
(
Object
*
obj
,
TypeImpl
*
target_typ
e
)
{
TypeImpl
*
target_type
;
if
(
typename
==
TYPE_OBJECT
)
{
return
true
;
}
target_type
=
type_get_by_name
(
typename
);
return
type_is_ancestor
(
obj
->
class
->
type
,
target_type
);
return
!
target_type
||
type_is_ancestor
(
obj
->
class
->
type
,
target_type
);
}
Object
*
object_dynamic_cast
(
Object
*
obj
,
const
char
*
typename
)
{
TypeImpl
*
target_type
=
type_get_by_name
(
typename
);
GSList
*
i
;
/* Check if typename is a direct ancestor. Special-case TYPE_OBJECT,
* we want to go back from interfaces to the parent.
*/
if
(
t
ypename
&&
object_is_type
(
obj
,
typenam
e
))
{
if
(
t
arget_type
&&
object_is_type
(
obj
,
target_typ
e
))
{
return
obj
;
}
...
...
@@ -410,21 +407,21 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
* ancestor of typename. In principle we could do this test at the very
* beginning of object_dynamic_cast, avoiding a second call to
* object_is_type. However, casting between interfaces is relatively
* rare, and object_is_type(obj,
TYPE_INTERFACE
) would fail almost always.
* rare, and object_is_type(obj,
type_interface
) would fail almost always.
*
* Perhaps we could add a magic value to the object header for increased
* (run-time) type safety and to speed up tests like this one. If we ever
* do that we can revisit the order here.
*/
if
(
object_is_type
(
obj
,
TYPE_INTERFACE
))
{
if
(
object_is_type
(
obj
,
type_interface
))
{
assert
(
!
obj
->
interfaces
);
obj
=
INTERFACE
(
obj
)
->
obj
;
if
(
object_is_type
(
obj
,
t
ypenam
e
))
{
if
(
object_is_type
(
obj
,
t
arget_typ
e
))
{
return
obj
;
}
}
if
(
typename
==
TYPE_OBJECT
)
{
if
(
!
target_type
)
{
return
obj
;
}
...
...
@@ -432,7 +429,7 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
for
(
i
=
obj
->
interfaces
;
i
;
i
=
i
->
next
)
{
Interface
*
iface
=
i
->
data
;
if
(
object_is_type
(
OBJECT
(
iface
),
t
ypenam
e
))
{
if
(
object_is_type
(
OBJECT
(
iface
),
t
arget_typ
e
))
{
return
OBJECT
(
iface
);
}
}
...
...
@@ -449,7 +446,7 @@ static void register_interface(void)
.
abstract
=
true
,
};
type_register_static
(
&
interface_info
);
type_
interface
=
type_
register_static
(
&
interface_info
);
}
device_init
(
register_interface
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录