Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1b613ff9
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1b613ff9
编写于
1月 29, 2013
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
librustc: Strdup unique strings instead of copying in byte by byte. Shaves 2MB off librustc at -O0.
上级
a47fa9b3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
7 deletion
+45
-7
src/libcore/rt.rs
src/libcore/rt.rs
+6
-1
src/librustc/middle/lang_items.rs
src/librustc/middle/lang_items.rs
+8
-2
src/librustc/middle/trans/tvec.rs
src/librustc/middle/trans/tvec.rs
+31
-4
未找到文件。
src/libcore/rt.rs
浏览文件 @
1b613ff9
...
...
@@ -14,7 +14,7 @@
//! Runtime calls emitted by the compiler.
use
cast
::
transmute
;
use
libc
::{
c_char
,
c_void
,
size_t
,
uintptr_t
};
use
libc
::{
c_char
,
c_
uchar
,
c_
void
,
size_t
,
uintptr_t
};
use
managed
::
raw
::
BoxRepr
;
use
str
;
use
sys
;
...
...
@@ -123,6 +123,11 @@ pub unsafe fn check_not_borrowed(a: *u8) {
}
}
#[lang=
"strdup_uniq"
]
pub
unsafe
fn
strdup_uniq
(
ptr
:
*
c_uchar
,
len
:
uint
)
->
~
str
{
str
::
raw
::
from_buf_len
(
ptr
,
len
)
}
// Local Variables:
// mode: rust;
// fill-column: 78;
...
...
src/librustc/middle/lang_items.rs
浏览文件 @
1b613ff9
...
...
@@ -74,16 +74,17 @@ pub enum LangItem {
BorrowAsImmFnLangItem
,
// 30
ReturnToMutFnLangItem
,
// 31
CheckNotBorrowedFnLangItem
,
// 32
StrDupUniqFnLangItem
,
// 33
}
struct
LanguageItems
{
items
:
[
Option
<
def_id
>
*
3
3
]
items
:
[
Option
<
def_id
>
*
3
4
]
}
impl
LanguageItems
{
static
pub
fn
new
()
->
LanguageItems
{
LanguageItems
{
items
:
[
None
,
..
3
3
]
items
:
[
None
,
..
3
4
]
}
}
...
...
@@ -133,6 +134,7 @@ fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) {
30
=>
"borrow_as_imm"
,
31
=>
"return_to_mut"
,
32
=>
"check_not_borrowed"
,
33
=>
"strdup_uniq"
,
_
=>
"???"
}
...
...
@@ -243,6 +245,9 @@ pub fn return_to_mut_fn(&const self) -> def_id {
pub
fn
check_not_borrowed_fn
(
&
const
self
)
->
def_id
{
self
.items
[
CheckNotBorrowedFnLangItem
as
uint
]
.get
()
}
pub
fn
strdup_uniq_fn
(
&
const
self
)
->
def_id
{
self
.items
[
StrDupUniqFnLangItem
as
uint
]
.get
()
}
}
fn
LanguageItemCollector
(
crate
:
@
crate
,
...
...
@@ -289,6 +294,7 @@ fn LanguageItemCollector(crate: @crate,
item_refs
.insert
(
~
"return_to_mut"
,
ReturnToMutFnLangItem
as
uint
);
item_refs
.insert
(
~
"check_not_borrowed"
,
CheckNotBorrowedFnLangItem
as
uint
);
item_refs
.insert
(
~
"strdup_uniq"
,
StrDupUniqFnLangItem
as
uint
);
LanguageItemCollector
{
crate
:
crate
,
...
...
src/librustc/middle/trans/tvec.rs
浏览文件 @
1b613ff9
...
...
@@ -276,10 +276,9 @@ fn trans_lit_str(bcx: block,
fn
trans_uniq_or_managed_vstore
(
bcx
:
block
,
heap
:
heap
,
vstore_expr
:
@
ast
::
expr
,
content_expr
:
@
ast
::
expr
)
->
DatumBlock
{
heap
:
heap
,
vstore_expr
:
@
ast
::
expr
,
content_expr
:
@
ast
::
expr
)
->
DatumBlock
{
//!
//
// @[...] or ~[...] (also @"..." or ~"...") allocate boxes in the
...
...
@@ -289,6 +288,34 @@ fn trans_uniq_or_managed_vstore(bcx: block,
bcx
.expr_to_str
(
vstore_expr
),
heap
);
let
_
indenter
=
indenter
();
// Handle ~"".
match
heap
{
heap_exchange
=>
{
match
content_expr
.node
{
ast
::
expr_lit
(
@
ast
::
spanned
{
node
:
ast
::
lit_str
(
s
),
_
})
=>
{
let
llptrval
=
C_cstr
(
bcx
.ccx
(),
copy
*
s
);
let
llptrval
=
PointerCast
(
bcx
,
llptrval
,
T_ptr
(
T_i8
()));
let
llsizeval
=
C_uint
(
bcx
.ccx
(),
s
.len
());
let
typ
=
ty
::
mk_estr
(
bcx
.tcx
(),
ty
::
vstore_uniq
);
let
lldestval
=
datum
::
scratch_datum
(
bcx
,
typ
,
false
);
let
bcx
=
callee
::
trans_rtcall_or_lang_call
(
bcx
,
bcx
.tcx
()
.lang_items
.strdup_uniq_fn
(),
~
[
llptrval
,
llsizeval
],
expr
::
SaveIn
(
lldestval
.to_ref_llval
(
bcx
)));
return
datum
::
DatumBlock
{
bcx
:
bcx
,
datum
:
lldestval
};
}
_
=>
{}
}
}
heap_shared
=>
{}
}
let
vt
=
vec_types_from_expr
(
bcx
,
vstore_expr
);
let
count
=
elements_required
(
bcx
,
content_expr
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录