Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
27f42288
Unverified
Commit
27f42288
authored
Jun 11, 2017
by
ksss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
To accurate `pos`
pos shouldn't cache because it's not controllable
parent
3a73a584
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
24 deletions
+8
-24
mrblib/io.rb
mrblib/io.rb
+8
-20
src/io.c
src/io.c
+0
-4
No files found.
mrblib/io.rb
View file @
27f42288
...
...
@@ -124,7 +124,6 @@ class IO
str
=
string
.
is_a?
(
String
)
?
string
:
string
.
to_s
return
str
.
size
unless
str
.
size
>
0
len
=
syswrite
(
str
)
@pos
+=
len
len
end
...
...
@@ -146,7 +145,7 @@ class IO
def
pos
raise
IOError
if
closed?
@pos
sysseek
(
0
,
SEEK_CUR
)
-
@buf
.
length
end
alias_method
:tell
,
:pos
...
...
@@ -160,7 +159,7 @@ class IO
def
seek
(
i
,
whence
=
SEEK_SET
)
raise
IOError
if
closed?
@pos
=
sysseek
(
i
,
whence
)
sysseek
(
i
,
whence
)
@buf
=
''
0
end
...
...
@@ -172,7 +171,6 @@ class IO
def
ungetc
(
substr
)
raise
TypeError
.
new
"expect String, got
#{
substr
.
class
}
"
unless
substr
.
is_a?
(
String
)
@pos
-=
substr
.
size
if
@buf
.
empty?
@buf
=
substr
.
dup
else
...
...
@@ -195,7 +193,6 @@ class IO
end
array
=
[]
start_pos
=
@pos
while
1
begin
_read_buf
...
...
@@ -204,15 +201,12 @@ class IO
break
end
if
length
&&
(
@pos
-
start_pos
+
@buf
.
size
)
>=
length
len
=
length
-
(
@pos
-
start_pos
)
array
.
push
@buf
[
0
,
len
]
@pos
+=
len
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
if
length
&&
length
<=
@buf
.
size
array
.
push
@buf
[
0
,
length
]
@buf
=
@buf
[
length
,
@buf
.
size
-
length
]
break
else
array
.
push
@buf
@pos
+=
@buf
.
size
@buf
=
''
end
end
...
...
@@ -240,7 +234,6 @@ class IO
end
array
=
[]
start_pos
=
@pos
while
1
begin
_read_buf
...
...
@@ -249,21 +242,17 @@ class IO
break
end
if
limit
&&
(
@pos
-
start_pos
+
@buf
.
size
)
>=
limit
len
=
limit
-
(
@pos
-
start_pos
)
array
.
push
@buf
[
0
,
len
]
@pos
+=
len
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
if
limit
&&
limit
<=
@buf
.
size
array
.
push
@buf
[
0
,
limit
]
@buf
=
@buf
[
limit
,
@buf
.
size
-
limit
]
break
elsif
idx
=
@buf
.
index
(
rs
)
len
=
idx
+
rs
.
size
array
.
push
@buf
[
0
,
len
]
@pos
+=
len
@buf
=
@buf
[
len
,
@buf
.
size
-
len
]
break
else
array
.
push
@buf
@pos
+=
@buf
.
size
@buf
=
''
end
end
...
...
@@ -285,7 +274,6 @@ class IO
_read_buf
c
=
@buf
[
0
]
@buf
=
@buf
[
1
,
@buf
.
size
]
@pos
+=
1
c
end
...
...
src/io.c
View file @
27f42288
...
...
@@ -389,7 +389,6 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
}
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr
=
mrb_io_alloc
(
mrb
);
fptr
->
fd
=
fd
;
...
...
@@ -443,7 +442,6 @@ mrb_io_initialize(mrb_state *mrb, mrb_value io)
flags
=
mrb_io_modestr_to_flags
(
mrb
,
mrb_string_value_cstr
(
mrb
,
&
mode
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
io
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr
=
(
struct
mrb_io
*
)
DATA_PTR
(
io
);
if
(
fptr
!=
NULL
)
{
...
...
@@ -801,7 +799,6 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
r
=
mrb_obj_value
(
mrb_data_object_alloc
(
mrb
,
mrb_class_ptr
(
klass
),
NULL
,
&
mrb_io_type
));
mrb_iv_set
(
mrb
,
r
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
r
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr_r
=
mrb_io_alloc
(
mrb
);
fptr_r
->
fd
=
pipes
[
0
];
fptr_r
->
readable
=
1
;
...
...
@@ -812,7 +809,6 @@ mrb_io_s_pipe(mrb_state *mrb, mrb_value klass)
w
=
mrb_obj_value
(
mrb_data_object_alloc
(
mrb
,
mrb_class_ptr
(
klass
),
NULL
,
&
mrb_io_type
));
mrb_iv_set
(
mrb
,
w
,
mrb_intern_cstr
(
mrb
,
"@buf"
),
mrb_str_new_cstr
(
mrb
,
""
));
mrb_iv_set
(
mrb
,
w
,
mrb_intern_cstr
(
mrb
,
"@pos"
),
mrb_fixnum_value
(
0
));
fptr_w
=
mrb_io_alloc
(
mrb
);
fptr_w
->
fd
=
pipes
[
1
];
fptr_w
->
readable
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment