Skip to content

Commit e4fff28

Browse files
committed
Optimize iconv_open(int, int).
修改: ChangeLog 修改: lib/iconv.cpp
1 parent 9ebf917 commit e4fff28

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-09-2 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
2+
3+
Optimize 'iconv_open(int, int)'.
4+
15
2023-08-29 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
26

37
Fix type-conflict warning when in clang.

lib/iconv.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,11 @@ static struct encoding const all_encodings[] = {
135135

136136
int lookup_by_codepage(int codepage)
137137
{
138-
size_t i1, i2;
139-
for(i1 = 0, i2 = sizeof(all_encodings) / sizeof(all_encodings[0]); i1 < i2; i1++, i2--)
138+
for(size_t i = 0; i < sizeof(all_encodings) / sizeof(all_encodings[0]); i++)
140139
{
141-
if(all_encodings[i1].codepage == codepage)
140+
if(all_encodings[i].codepage == codepage)
142141
{
143-
return i1;
144-
}
145-
if(all_encodings[i2].codepage == codepage)
146-
{
147-
return i2;
142+
return i;
148143
}
149144
}
150145
return -1;
@@ -281,7 +276,7 @@ iconv_t iconv_open(int tocode_cp, int fromcode_cp, bool strict)
281276
to_index = lookup_by_codepage(tocode_cp);
282277
from_index = lookup_by_codepage(fromcode_cp);
283278

284-
if(to_index == -1 || from_index == -1)
279+
if(to_index == -1 || from_index == -1 || tocode_cp == -1 || fromcode_cp == -1)
285280
{
286281
errno = EINVAL;
287282
return (iconv_t)(-1);

0 commit comments

Comments
 (0)