Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nccf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
702
Provoz
nccf
Commits
e9c8d12c
Commit
e9c8d12c
authored
3 years ago
by
Yorhel
Browse files
Options
Downloads
Patches
Plain Diff
Store Ext before Entry
Which is slightly simpler and should provide a minor performance improvement.
parent
5a196125
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
build.zig
+1
-0
1 addition, 0 deletions
build.zig
src/model.zig
+15
-18
15 additions, 18 deletions
src/model.zig
with
16 additions
and
18 deletions
build.zig
+
1
−
0
View file @
e9c8d12c
...
@@ -24,6 +24,7 @@ pub fn build(b: *std.build.Builder) void {
...
@@ -24,6 +24,7 @@ pub fn build(b: *std.build.Builder) void {
const
tst
=
b
.
addTest
(
"src/main.zig"
);
const
tst
=
b
.
addTest
(
"src/main.zig"
);
tst
.
linkLibC
();
tst
.
linkLibC
();
tst
.
linkSystemLibrary
(
"ncursesw"
);
tst
.
linkSystemLibrary
(
"ncursesw"
);
tst
.
addCSourceFile
(
"src/ncurses_refs.c"
,
&
[
_
][]
const
u8
{});
const
tst_step
=
b
.
step
(
"test"
,
"Run tests"
);
const
tst_step
=
b
.
step
(
"test"
,
"Run tests"
);
tst_step
.
dependOn
(
&
tst
.
step
);
tst_step
.
dependOn
(
&
tst
.
step
);
}
}
This diff is collapsed.
Click to expand it.
src/model.zig
+
15
−
18
View file @
e9c8d12c
...
@@ -17,20 +17,18 @@ pub const EType = packed enum(u2) { dir, link, file };
...
@@ -17,20 +17,18 @@ pub const EType = packed enum(u2) { dir, link, file };
pub
const
Blocks
=
u60
;
pub
const
Blocks
=
u60
;
// Memory layout:
// Memory layout:
// Dir + name
(+ alignment + Ext)
//
(Ext +)
Dir + name
// or: Link + name
(+ alignment + Ext)
// or:
(Ext +)
Link + name
// or: File + name
(+ alignment + Ext)
// or:
(Ext +)
File + name
//
//
// Entry is always the first part of Dir, Link and File, so a pointer cast to
// Entry is always the first part of Dir, Link and File, so a pointer cast to
// *Entry is always safe and an *Entry can be casted to the full type.
// *Entry is always safe and an *Entry can be casted to the full type. The Ext
// struct, if present, is placed before the *Entry pointer.
// These are all packed structs and hence do not have any alignment, which is
// great for saving memory but perhaps not very great for code size or
// performance.
// (TODO: What are the aliassing rules for Zig? There is a 'noalias' keyword,
// (TODO: What are the aliassing rules for Zig? There is a 'noalias' keyword,
// but does that mean all unmarked pointers are allowed to alias?)
// but does that mean all unmarked pointers are allowed to alias?)
// (TODO: The 'alignment' in the layout above is a lie, none of these structs
// or fields have any sort of alignment. This is great for saving memory but
// perhaps not very great for code size or performance. Might want to
// experiment with setting some alignment and measure the impact)
// (TODO: Putting Ext before the Entry pointer may be a little faster; removes
// the need to iterate over the name)
pub
const
Entry
=
packed
struct
{
pub
const
Entry
=
packed
struct
{
etype
:
EType
,
etype
:
EType
,
isext
:
bool
,
isext
:
bool
,
...
@@ -68,32 +66,31 @@ pub const Entry = packed struct {
...
@@ -68,32 +66,31 @@ pub const Entry = packed struct {
}
}
pub
fn
name
(
self
:
*
const
Self
)
[:
0
]
const
u8
{
pub
fn
name
(
self
:
*
const
Self
)
[:
0
]
const
u8
{
const
ptr
=
@
intToPtr
([
*
:
0
]
u8
,
@ptrToInt
(
self
)
+
nameOffset
(
self
.
etype
)
)
;
const
ptr
=
@
ptrCast
([
*
:
0
]
const
u8
,
self
)
+
nameOffset
(
self
.
etype
);
return
ptr
[
0
..
std
.
mem
.
lenZ
(
ptr
)
:
0
];
return
ptr
[
0
..
std
.
mem
.
lenZ
(
ptr
)
:
0
];
}
}
pub
fn
ext
(
self
:
*
Self
)
?*
Ext
{
pub
fn
ext
(
self
:
*
Self
)
?*
Ext
{
if
(
!
self
.
isext
)
return
null
;
if
(
!
self
.
isext
)
return
null
;
const
n
=
self
.
name
();
return
@ptrCast
(
*
Ext
,
@ptrCast
([
*
]
Ext
,
self
)
-
1
);
return
@intToPtr
(
*
Ext
,
std
.
mem
.
alignForward
(
@ptrToInt
(
self
)
+
nameOffset
(
self
.
etype
)
+
n
.
len
+
1
,
@alignOf
(
Ext
)));
}
}
pub
fn
create
(
etype
:
EType
,
isext
:
bool
,
ename
:
[]
const
u8
)
*
Entry
{
pub
fn
create
(
etype
:
EType
,
isext
:
bool
,
ename
:
[]
const
u8
)
*
Entry
{
const
base_
size
=
nameOffset
(
etype
)
+
ename
.
len
+
1
;
const
ext
size
=
if
(
isext
)
@as
(
usize
,
@sizeOf
(
Ext
))
else
0
;
const
size
=
(
if
(
isext
)
std
.
mem
.
alignForward
(
base_size
,
@alignOf
(
Ext
))
+
@sizeOf
(
Ext
)
else
base_
size
)
;
const
size
=
nameOffset
(
etype
)
+
ename
.
len
+
1
+
ext
size
;
var
ptr
=
blk
:
{
var
ptr
=
blk
:
{
while
(
true
)
{
while
(
true
)
{
if
(
allocator
.
allocator
.
allocWithOptions
(
u8
,
size
,
@alignOf
(
Entry
),
null
))
|
p
|
if
(
allocator
.
allocator
.
allocWithOptions
(
u8
,
size
,
std
.
math
.
max
(
@alignOf
(
Ext
),
@alignOf
(
Entry
)
)
,
null
))
|
p
|
break
:
blk
p
break
:
blk
p
else
|
_
|
{}
else
|
_
|
{}
ui
.
oom
();
ui
.
oom
();
}
}
};
};
std
.
mem
.
set
(
u8
,
ptr
,
0
);
// kind of ugly, but does the trick
std
.
mem
.
set
(
u8
,
ptr
,
0
);
// kind of ugly, but does the trick
var
e
=
@ptrCast
(
*
Entry
,
ptr
);
var
e
=
@ptrCast
(
*
Entry
,
ptr
.
ptr
+
extsize
);
e
.
etype
=
etype
;
e
.
etype
=
etype
;
e
.
isext
=
isext
;
e
.
isext
=
isext
;
var
name_ptr
=
@
intToPtr
([
*
]
u8
,
@ptrToInt
(
e
)
+
nameOffset
(
etype
)
)
;
var
name_ptr
=
@
ptrCast
([
*
]
u8
,
e
)
+
nameOffset
(
etype
);
std
.
mem
.
copy
(
u8
,
name_ptr
[
0
..
ename
.
len
],
ename
);
std
.
mem
.
copy
(
u8
,
name_ptr
[
0
..
ename
.
len
],
ename
);
return
e
;
return
e
;
}
}
...
...
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