Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f0adc393
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f0adc393
编写于
4月 01, 2019
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use VS Buffer
上级
a42d4d21
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
2 addition
and
117 deletion
+2
-117
src/vs/base/common/uint.ts
src/vs/base/common/uint.ts
+0
-112
src/vs/workbench/services/output/common/outputChannelModel.ts
...vs/workbench/services/output/common/outputChannelModel.ts
+2
-5
未找到文件。
src/vs/base/common/uint.ts
已删除
100644 → 0
浏览文件 @
a42d4d21
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export
function
toUint8ArrayBuffer
(
str
:
string
):
ArrayBuffer
{
if
(
typeof
TextEncoder
!==
'
undefined
'
)
{
return
new
TextEncoder
().
encode
(
str
).
buffer
;
}
let
i
:
number
,
len
:
number
,
length
=
0
,
charCode
=
0
,
trailCharCode
=
0
,
codepoint
=
0
;
// First pass, for the size
for
(
i
=
0
,
len
=
str
.
length
;
i
<
len
;
i
++
)
{
charCode
=
str
.
charCodeAt
(
i
);
// Surrogate pair
if
(
charCode
>=
0xD800
&&
charCode
<
0xDC00
)
{
trailCharCode
=
str
.
charCodeAt
(
++
i
);
if
(
!
(
trailCharCode
>=
0xDC00
&&
trailCharCode
<
0xE000
))
{
throw
new
Error
(
'
Invalid char code
'
);
}
// Code point can be obtained by subtracting 0xD800 and 0xDC00 from both char codes respectively
// and joining the 10 least significant bits from each, finally adding 0x10000.
codepoint
=
((((
charCode
-
0xD800
)
&
0x3FF
)
<<
10
)
|
((
trailCharCode
-
0xDC00
)
&
0x3FF
))
+
0x10000
;
}
else
{
codepoint
=
charCode
;
}
length
+=
byteSizeInUTF8
(
codepoint
);
}
let
result
=
new
ArrayBuffer
(
length
);
let
view
=
new
Uint8Array
(
result
);
let
pos
=
0
;
// Second pass, for the data
for
(
i
=
0
,
len
=
str
.
length
;
i
<
len
;
i
++
)
{
charCode
=
str
.
charCodeAt
(
i
);
if
(
charCode
>=
0xD800
&&
charCode
<
0xDC00
)
{
trailCharCode
=
str
.
charCodeAt
(
++
i
);
codepoint
=
((((
charCode
-
0xD800
)
&
0x3FF
)
<<
10
)
|
((
trailCharCode
-
0xDC00
)
&
0x3FF
))
+
0x10000
;
}
else
{
codepoint
=
charCode
;
}
pos
+=
writeUTF8
(
codepoint
,
view
,
pos
);
}
return
result
;
}
function
byteSizeInUTF8
(
codePoint
:
number
):
number
{
codePoint
=
codePoint
>>>
0
;
if
(
codePoint
<
0x80
)
{
return
1
;
}
else
if
(
codePoint
<
0x800
)
{
return
2
;
}
else
if
(
codePoint
<
0x10000
)
{
return
3
;
}
else
if
(
codePoint
<
0x200000
)
{
return
4
;
}
else
if
(
codePoint
<
0x4000000
)
{
return
5
;
}
else
if
(
codePoint
<
0x80000000
)
{
return
6
;
}
else
{
throw
new
Error
(
'
Code point 0x
'
+
toHexString
(
codePoint
)
+
'
not encodable in UTF8.
'
);
}
}
function
writeUTF8
(
codePoint
:
number
,
buffer
:
Uint8Array
,
pos
:
number
):
number
{
// How many bits needed for codePoint
let
byteSize
=
byteSizeInUTF8
(
codePoint
);
// 0xxxxxxx
if
(
byteSize
===
1
)
{
buffer
[
pos
]
=
codePoint
;
return
1
;
}
// 110xxxxx 10xxxxxx
// 1110xxxx 10xxxxxx 10xxxxxx
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// first byte
buffer
[
pos
]
=
((
0xFC
<<
(
6
-
byteSize
))
|
(
codePoint
>>>
(
6
*
(
byteSize
-
1
))))
&
0xFF
;
// successive bytes
for
(
let
i
=
1
;
i
<
byteSize
;
i
++
)
{
buffer
[
pos
+
i
]
=
(
0x80
|
(
0x3F
&
(
codePoint
>>>
(
6
*
(
byteSize
-
i
-
1
)))))
&
0xFF
;
}
return
byteSize
;
}
function
leftPad
(
value
:
string
,
length
:
number
,
char
:
string
=
'
0
'
):
string
{
return
new
Array
(
length
-
value
.
length
+
1
).
join
(
char
)
+
value
;
}
function
toHexString
(
value
:
number
,
bitsize
:
number
=
32
):
string
{
return
leftPad
((
value
>>>
0
).
toString
(
16
),
bitsize
/
4
);
}
src/vs/workbench/services/output/common/outputChannelModel.ts
浏览文件 @
f0adc393
...
...
@@ -17,7 +17,7 @@ import { isNumber } from 'vs/base/common/types';
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
binarySearch
}
from
'
vs/base/common/arrays
'
;
import
{
toUint8ArrayBuffer
}
from
'
vs/base/common/uint
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
export
interface
IOutputChannelModel
extends
IDisposable
{
readonly
onDidAppendedContent
:
Event
<
void
>
;
...
...
@@ -259,10 +259,7 @@ class FileOutputChannelModel extends AbstractFileOutputChannelModel implements I
}
protected
getByteLength
(
str
:
string
):
number
{
if
(
typeof
Buffer
!==
'
undefined
'
)
{
return
Buffer
.
from
(
str
).
byteLength
;
}
return
toUint8ArrayBuffer
(
str
).
byteLength
;
return
VSBuffer
.
fromString
(
str
).
byteLength
;
}
update
(
size
?:
number
):
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录