Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fzf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
fzf
Commits
37370f05
Unverified
Commit
37370f05
authored
7 years ago
by
Junegunn Choi
Browse files
Options
Downloads
Patches
Plain Diff
Do not use defer in performance-sensitive contexts
parent
f4b46fad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/chunklist.go
+4
-2
4 additions, 2 deletions
src/chunklist.go
src/core.go
+1
-1
1 addition, 1 deletion
src/core.go
src/util/eventbox.go
+5
-5
5 additions, 5 deletions
src/util/eventbox.go
with
10 additions
and
8 deletions
src/chunklist.go
+
4
−
2
View file @
37370f05
...
@@ -55,7 +55,6 @@ func CountItems(cs []*Chunk) int {
...
@@ -55,7 +55,6 @@ func CountItems(cs []*Chunk) int {
// Push adds the item to the list
// Push adds the item to the list
func
(
cl
*
ChunkList
)
Push
(
data
[]
byte
)
bool
{
func
(
cl
*
ChunkList
)
Push
(
data
[]
byte
)
bool
{
cl
.
mutex
.
Lock
()
cl
.
mutex
.
Lock
()
defer
cl
.
mutex
.
Unlock
()
if
len
(
cl
.
chunks
)
==
0
||
cl
.
lastChunk
()
.
IsFull
()
{
if
len
(
cl
.
chunks
)
==
0
||
cl
.
lastChunk
()
.
IsFull
()
{
newChunk
:=
Chunk
(
make
([]
Item
,
0
,
chunkSize
))
newChunk
:=
Chunk
(
make
([]
Item
,
0
,
chunkSize
))
...
@@ -64,15 +63,16 @@ func (cl *ChunkList) Push(data []byte) bool {
...
@@ -64,15 +63,16 @@ func (cl *ChunkList) Push(data []byte) bool {
if
cl
.
lastChunk
()
.
push
(
cl
.
trans
,
data
,
cl
.
count
)
{
if
cl
.
lastChunk
()
.
push
(
cl
.
trans
,
data
,
cl
.
count
)
{
cl
.
count
++
cl
.
count
++
cl
.
mutex
.
Unlock
()
return
true
return
true
}
}
cl
.
mutex
.
Unlock
()
return
false
return
false
}
}
// Snapshot returns immutable snapshot of the ChunkList
// Snapshot returns immutable snapshot of the ChunkList
func
(
cl
*
ChunkList
)
Snapshot
()
([]
*
Chunk
,
int
)
{
func
(
cl
*
ChunkList
)
Snapshot
()
([]
*
Chunk
,
int
)
{
cl
.
mutex
.
Lock
()
cl
.
mutex
.
Lock
()
defer
cl
.
mutex
.
Unlock
()
ret
:=
make
([]
*
Chunk
,
len
(
cl
.
chunks
))
ret
:=
make
([]
*
Chunk
,
len
(
cl
.
chunks
))
copy
(
ret
,
cl
.
chunks
)
copy
(
ret
,
cl
.
chunks
)
...
@@ -82,5 +82,7 @@ func (cl *ChunkList) Snapshot() ([]*Chunk, int) {
...
@@ -82,5 +82,7 @@ func (cl *ChunkList) Snapshot() ([]*Chunk, int) {
newChunk
:=
*
ret
[
cnt
-
1
]
newChunk
:=
*
ret
[
cnt
-
1
]
ret
[
cnt
-
1
]
=
&
newChunk
ret
[
cnt
-
1
]
=
&
newChunk
}
}
cl
.
mutex
.
Unlock
()
return
ret
,
cl
.
count
return
ret
,
cl
.
count
}
}
This diff is collapsed.
Click to expand it.
src/core.go
+
1
−
1
View file @
37370f05
...
@@ -205,7 +205,6 @@ func Run(opts *Options, revision string) {
...
@@ -205,7 +205,6 @@ func Run(opts *Options, revision string) {
delay
:=
true
delay
:=
true
ticks
++
ticks
++
eventBox
.
Wait
(
func
(
events
*
util
.
Events
)
{
eventBox
.
Wait
(
func
(
events
*
util
.
Events
)
{
defer
events
.
Clear
()
for
evt
,
value
:=
range
*
events
{
for
evt
,
value
:=
range
*
events
{
switch
evt
{
switch
evt
{
...
@@ -265,6 +264,7 @@ func Run(opts *Options, revision string) {
...
@@ -265,6 +264,7 @@ func Run(opts *Options, revision string) {
}
}
}
}
}
}
events
.
Clear
()
})
})
if
delay
&&
reading
{
if
delay
&&
reading
{
dur
:=
util
.
DurWithin
(
dur
:=
util
.
DurWithin
(
...
...
This diff is collapsed.
Click to expand it.
src/util/eventbox.go
+
5
−
5
View file @
37370f05
...
@@ -26,23 +26,23 @@ func NewEventBox() *EventBox {
...
@@ -26,23 +26,23 @@ func NewEventBox() *EventBox {
// Wait blocks the goroutine until signaled
// Wait blocks the goroutine until signaled
func
(
b
*
EventBox
)
Wait
(
callback
func
(
*
Events
))
{
func
(
b
*
EventBox
)
Wait
(
callback
func
(
*
Events
))
{
b
.
cond
.
L
.
Lock
()
b
.
cond
.
L
.
Lock
()
defer
b
.
cond
.
L
.
Unlock
()
if
len
(
b
.
events
)
==
0
{
if
len
(
b
.
events
)
==
0
{
b
.
cond
.
Wait
()
b
.
cond
.
Wait
()
}
}
callback
(
&
b
.
events
)
callback
(
&
b
.
events
)
b
.
cond
.
L
.
Unlock
()
}
}
// Set turns on the event type on the box
// Set turns on the event type on the box
func
(
b
*
EventBox
)
Set
(
event
EventType
,
value
interface
{})
{
func
(
b
*
EventBox
)
Set
(
event
EventType
,
value
interface
{})
{
b
.
cond
.
L
.
Lock
()
b
.
cond
.
L
.
Lock
()
defer
b
.
cond
.
L
.
Unlock
()
b
.
events
[
event
]
=
value
b
.
events
[
event
]
=
value
if
_
,
found
:=
b
.
ignore
[
event
];
!
found
{
if
_
,
found
:=
b
.
ignore
[
event
];
!
found
{
b
.
cond
.
Broadcast
()
b
.
cond
.
Broadcast
()
}
}
b
.
cond
.
L
.
Unlock
()
}
}
// Clear clears the events
// Clear clears the events
...
@@ -56,27 +56,27 @@ func (events *Events) Clear() {
...
@@ -56,27 +56,27 @@ func (events *Events) Clear() {
// Peek peeks at the event box if the given event is set
// Peek peeks at the event box if the given event is set
func
(
b
*
EventBox
)
Peek
(
event
EventType
)
bool
{
func
(
b
*
EventBox
)
Peek
(
event
EventType
)
bool
{
b
.
cond
.
L
.
Lock
()
b
.
cond
.
L
.
Lock
()
defer
b
.
cond
.
L
.
Unlock
()
_
,
ok
:=
b
.
events
[
event
]
_
,
ok
:=
b
.
events
[
event
]
b
.
cond
.
L
.
Unlock
()
return
ok
return
ok
}
}
// Watch deletes the events from the ignore list
// Watch deletes the events from the ignore list
func
(
b
*
EventBox
)
Watch
(
events
...
EventType
)
{
func
(
b
*
EventBox
)
Watch
(
events
...
EventType
)
{
b
.
cond
.
L
.
Lock
()
b
.
cond
.
L
.
Lock
()
defer
b
.
cond
.
L
.
Unlock
()
for
_
,
event
:=
range
events
{
for
_
,
event
:=
range
events
{
delete
(
b
.
ignore
,
event
)
delete
(
b
.
ignore
,
event
)
}
}
b
.
cond
.
L
.
Unlock
()
}
}
// Unwatch adds the events to the ignore list
// Unwatch adds the events to the ignore list
func
(
b
*
EventBox
)
Unwatch
(
events
...
EventType
)
{
func
(
b
*
EventBox
)
Unwatch
(
events
...
EventType
)
{
b
.
cond
.
L
.
Lock
()
b
.
cond
.
L
.
Lock
()
defer
b
.
cond
.
L
.
Unlock
()
for
_
,
event
:=
range
events
{
for
_
,
event
:=
range
events
{
b
.
ignore
[
event
]
=
true
b
.
ignore
[
event
]
=
true
}
}
b
.
cond
.
L
.
Unlock
()
}
}
// WaitFor blocks the execution until the event is received
// WaitFor blocks the execution until the event is received
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment