Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
videolan
vlc-2-2
Commits
72149942
Commit
72149942
authored
Aug 03, 2010
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vlc_loaddir: avoid realloc at every iteration
parent
04ad4fc7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
33 deletions
+38
-33
src/text/filesystem.c
src/text/filesystem.c
+38
-33
No files found.
src/text/filesystem.c
View file @
72149942
...
@@ -353,54 +353,59 @@ int vlc_loaddir( DIR *dir, char ***namelist,
...
@@ -353,54 +353,59 @@ int vlc_loaddir( DIR *dir, char ***namelist,
int
(
*
select
)(
const
char
*
),
int
(
*
select
)(
const
char
*
),
int
(
*
compar
)(
const
char
**
,
const
char
**
)
)
int
(
*
compar
)(
const
char
**
,
const
char
**
)
)
{
{
if
(
select
==
NULL
)
assert
(
dir
);
if
(
select
==
NULL
)
select
=
dummy_select
;
select
=
dummy_select
;
if
(
dir
==
NULL
)
return
-
1
;
else
{
char
**
tab
=
NULL
;
char
**
tab
=
NULL
;
char
*
entry
;
unsigned
num
=
0
;
unsigned
num
=
0
;
rewinddir
(
dir
);
rewinddir
(
dir
);
while
(
(
entry
=
vlc_readdir
(
dir
)
)
!=
NULL
)
for
(
unsigned
size
=
0
;;
)
{
{
char
**
newtab
;
errno
=
0
;
char
*
entry
=
vlc_readdir
(
dir
);
if
(
entry
==
NULL
)
{
if
(
errno
)
goto
error
;
break
;
}
if
(
!
select
(
entry
)
)
if
(
!
select
(
entry
)
)
{
{
free
(
entry
);
free
(
entry
);
continue
;
continue
;
}
}
newtab
=
realloc
(
tab
,
sizeof
(
char
*
)
*
(
num
+
1
)
);
if
(
num
>=
size
)
if
(
newtab
==
NULL
)
{
{
free
(
entry
);
size
=
size
?
(
2
*
size
)
:
16
;
char
**
newtab
=
realloc
(
tab
,
sizeof
(
*
tab
)
*
(
size
));
if
(
unlikely
(
newtab
==
NULL
))
{
free
(
entry
);
goto
error
;
goto
error
;
}
}
tab
=
newtab
;
tab
=
newtab
;
tab
[
num
++
]
=
entry
;
}
}
if
(
compar
!=
NULL
)
tab
[
num
++
]
=
entry
;
qsort
(
tab
,
num
,
sizeof
(
tab
[
0
]
),
}
(
int
(
*
)(
const
void
*
,
const
void
*
))
compar
);
if
(
compar
!=
NULL
)
qsort
(
tab
,
num
,
sizeof
(
*
tab
),
(
int
(
*
)(
const
void
*
,
const
void
*
))
compar
);
*
namelist
=
tab
;
*
namelist
=
tab
;
return
num
;
return
num
;
error:
{
error:
unsigned
i
;
for
(
unsigned
i
=
0
;
i
<
num
;
i
++
)
free
(
tab
[
i
]);
for
(
i
=
0
;
i
<
num
;
i
++
)
free
(
tab
);
free
(
tab
[
i
]
);
free
(
tab
);
}
}
return
-
1
;
return
-
1
;
}
}
...
...
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