Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 932669b

Browse files
committed
Drop STRLEN() macros
There is no need in STRLEN macros. Compilers can do this trivial optimization on its own. Signed-off-by: Kirill A. Shutemov <[email protected]>
1 parent a7e34e3 commit 932669b

14 files changed

+34
-36
lines changed

src/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
225225

226226
if (git__prefixcmp(buffer, "encoding ") == 0) {
227227
const char *encoding_end;
228-
buffer += STRLEN("encoding ");
228+
buffer += strlen("encoding ");
229229

230230
encoding_end = buffer;
231231
while (encoding_end < buffer_end && *encoding_end != '\n')

src/config_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static char *interiorize_section(const char *orig)
264264
len = dot - orig;
265265
memcpy(section, orig, len);
266266
section += len;
267-
len = STRLEN(" \"");
267+
len = strlen(" \"");
268268
memcpy(section, " \"", len);
269269
section += len;
270270
len = last_dot - dot - 1;

src/indexer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ static void index_path(char *path, git_indexer *idx)
176176

177177
ptr = strrchr(path, '/') + 1;
178178

179-
memcpy(ptr, prefix, STRLEN(prefix));
180-
ptr += STRLEN(prefix);
179+
memcpy(ptr, prefix, strlen(prefix));
180+
ptr += strlen(prefix);
181181
git_oid_fmt(ptr, &idx->hash);
182182
ptr += GIT_OID_HEXSZ;
183-
memcpy(ptr, suffix, STRLEN(suffix));
183+
memcpy(ptr, suffix, strlen(suffix));
184184
}
185185

186186
int git_indexer_write(git_indexer *idx)
@@ -199,7 +199,7 @@ int git_indexer_write(git_indexer *idx)
199199

200200
namelen = strlen(idx->pack->pack_name);
201201
memcpy(filename, idx->pack->pack_name, namelen);
202-
memcpy(filename + namelen - STRLEN("pack"), "idx\0", STRLEN("idx\0"));
202+
memcpy(filename + namelen - strlen("pack"), "idx", strlen("idx") + 1);
203203

204204
error = git_filebuf_open(&idx->file, filename, GIT_FILEBUF_HASH_CONTENTS);
205205

src/odb_pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static int packfile_load__cb(void *_data, char *path)
237237

238238
for (i = 0; i < backend->packs.length; ++i) {
239239
struct git_pack_file *p = git_vector_get(&backend->packs, i);
240-
if (memcmp(p->pack_name, path, strlen(path) - STRLEN(".idx")) == 0)
240+
if (memcmp(p->pack_name, path, strlen(path) - strlen(".idx")) == 0)
241241
return GIT_SUCCESS;
242242
}
243243

src/pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int pack_index_open(struct git_pack_file *p)
196196
return GIT_SUCCESS;
197197

198198
idx_name = git__strdup(p->pack_name);
199-
strcpy(idx_name + strlen(idx_name) - STRLEN(".pack"), ".idx");
199+
strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx");
200200

201201
error = pack_index_check(idx_name, p);
202202
free(idx_name);
@@ -614,7 +614,7 @@ int git_packfile_check(struct git_pack_file **pack_out, const char *path)
614614
* Make sure a corresponding .pack file exists and that
615615
* the index looks sane.
616616
*/
617-
path_len -= STRLEN(".idx");
617+
path_len -= strlen(".idx");
618618
if (path_len < 1) {
619619
free(p);
620620
return git__throw(GIT_ENOTFOUND, "Failed to check packfile. Wrong path name");

src/pkt.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ int git_pkt_send_flush(int s)
267267
{
268268
char flush[] = "0000";
269269

270-
return gitno_send(s, flush, STRLEN(flush), 0);
270+
return gitno_send(s, flush, strlen(flush), 0);
271271
}
272272

273273
static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, int fd)
@@ -279,7 +279,7 @@ static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps,
279279
if (caps->ofs_delta)
280280
strcpy(capstr, GIT_CAP_OFS_DELTA);
281281

282-
len = STRLEN("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */;
282+
len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */;
283283
cmd = git__malloc(len + 1);
284284
if (cmd == NULL)
285285
return GIT_ENOMEM;
@@ -302,10 +302,10 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
302302
{
303303
unsigned int i = 0;
304304
int error = GIT_SUCCESS;
305-
char buf[STRLEN(WANT_PREFIX) + GIT_OID_HEXSZ + 2];
305+
char buf[strlen(WANT_PREFIX) + GIT_OID_HEXSZ + 2];
306306
git_remote_head *head;
307307

308-
memcpy(buf, WANT_PREFIX, STRLEN(WANT_PREFIX));
308+
memcpy(buf, WANT_PREFIX, strlen(WANT_PREFIX));
309309
buf[sizeof(buf) - 2] = '\n';
310310
buf[sizeof(buf) - 1] = '\0';
311311

@@ -332,8 +332,8 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
332332
if (head->local)
333333
continue;
334334

335-
git_oid_fmt(buf + STRLEN(WANT_PREFIX), &head->oid);
336-
error = gitno_send(fd, buf, STRLEN(buf), 0);
335+
git_oid_fmt(buf + strlen(WANT_PREFIX), &head->oid);
336+
error = gitno_send(fd, buf, strlen(buf), 0);
337337
return git__rethrow(error, "Failed to send want pkt");
338338
}
339339

@@ -350,13 +350,13 @@ int git_pkt_send_have(git_oid *oid, int fd)
350350
{
351351
char buf[] = "0032have 0000000000000000000000000000000000000000\n";
352352

353-
git_oid_fmt(buf + STRLEN(HAVE_PREFIX), oid);
354-
return gitno_send(fd, buf, STRLEN(buf), 0);
353+
git_oid_fmt(buf + strlen(HAVE_PREFIX), oid);
354+
return gitno_send(fd, buf, strlen(buf), 0);
355355
}
356356

357357
int git_pkt_send_done(int fd)
358358
{
359359
char buf[] = "0009done\n";
360360

361-
return gitno_send(fd, buf, STRLEN(buf), 0);
361+
return gitno_send(fd, buf, strlen(buf), 0);
362362
}

src/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
9393
}
9494

9595
/* "fetch" is the longest var name we're interested in */
96-
buf_len = STRLEN("remote.") + STRLEN(".fetch") + strlen(name) + 1;
96+
buf_len = strlen("remote.") + strlen(".fetch") + strlen(name) + 1;
9797
buf = git__malloc(buf_len);
9898
if (buf == NULL) {
9999
error = GIT_ENOMEM;

src/repository.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,12 @@ static int read_gitfile(char *path_out, const char *file_path, const char *base_
449449
for (;data[end_offset] == '\r' || data[end_offset] == '\n'; --end_offset);
450450
data[end_offset + 1] = '\0';
451451

452-
if (STRLEN(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) {
452+
if (strlen(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) {
453453
git_futils_freebuffer(&file);
454454
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
455455
}
456456

457-
data = data + STRLEN(GIT_FILE_CONTENT_PREFIX);
457+
data = data + strlen(GIT_FILE_CONTENT_PREFIX);
458458
error = git_path_prettify_dir(path_out, data, base_path);
459459
git_futils_freebuffer(&file);
460460

src/revwalk.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
183183

184184
static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw)
185185
{
186-
const int parent_len = STRLEN("parent ") + GIT_OID_HEXSZ + 1;
186+
const int parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
187187

188188
unsigned char *buffer = raw->data;
189189
unsigned char *buffer_end = buffer + raw->len;
@@ -192,10 +192,10 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
192192
int i, parents = 0;
193193
long commit_time;
194194

195-
buffer += STRLEN("tree ") + GIT_OID_HEXSZ + 1;
195+
buffer += strlen("tree ") + GIT_OID_HEXSZ + 1;
196196

197197
parents_start = buffer;
198-
while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", STRLEN("parent ")) == 0) {
198+
while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) {
199199
parents++;
200200
buffer += parent_len;
201201
}
@@ -208,7 +208,7 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
208208
for (i = 0; i < parents; ++i) {
209209
git_oid oid;
210210

211-
if (git_oid_fromstr(&oid, (char *)buffer + STRLEN("parent ")) < GIT_SUCCESS)
211+
if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < GIT_SUCCESS)
212212
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse commit. Parent object is corrupted");
213213

214214
commit->parents[i] = commit_lookup(walk, &oid);

src/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ typedef struct {
388388
const char *pattern;
389389
} tag_filter_data;
390390

391-
#define GIT_REFS_TAGS_DIR_LEN STRLEN(GIT_REFS_TAGS_DIR)
391+
#define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR)
392392

393393
static int tag_list_cb(const char *tag_name, void *payload)
394394
{

src/transport_git.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int gen_proto(char **out, int *outlen, const char *cmd, const char *url)
7373
if (cmd == NULL)
7474
cmd = default_command;
7575

76-
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + STRLEN(host) + (delim - url) + 2;
76+
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 2;
7777

7878
*out = git__malloc(len);
7979
if (*out == NULL)
@@ -148,7 +148,7 @@ static int do_connect(transport_git *t, const char *url)
148148
int error, connected = 0;
149149

150150
if (!git__prefixcmp(url, prefix))
151-
url += STRLEN(prefix);
151+
url += strlen(prefix);
152152

153153
error = extract_host_and_port(&host, &port, url);
154154
s = gitno_connect(host, port);
@@ -242,7 +242,7 @@ static int detect_caps(transport_git *t)
242242

243243
if(!git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) {
244244
caps->common = caps->ofs_delta = 1;
245-
ptr += STRLEN(GIT_CAP_OFS_DELTA);
245+
ptr += strlen(GIT_CAP_OFS_DELTA);
246246
continue;
247247
}
248248

@@ -474,9 +474,9 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
474474
strcpy(path, repo->path_repository);
475475
off += strlen(repo->path_repository);
476476
strcat(path, suff);
477-
//memcpy(path + off, suff, GIT_PATH_MAX - off - STRLEN(suff) - 1);
477+
//memcpy(path + off, suff, GIT_PATH_MAX - off - strlen(suff) - 1);
478478

479-
if (memcmp(buf->data, "PACK", STRLEN("PACK"))) {
479+
if (memcmp(buf->data, "PACK", strlen("PACK"))) {
480480
return git__throw(GIT_ERROR, "The pack doesn't start with the signature");
481481
}
482482

src/transport_local.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int local_connect(git_transport *transport, int GIT_UNUSED(direction))
3131

3232
/* The repo layer doesn't want the prefix */
3333
if (!git__prefixcmp(transport->url, file_prefix))
34-
path = transport->url + STRLEN(file_prefix);
34+
path = transport->url + strlen(file_prefix);
3535
else
3636
path = transport->url;
3737

@@ -92,7 +92,7 @@ static int add_ref(const char *name, git_repository *repo, git_vector *vec)
9292

9393
/* And if it's a tag, peel it, and add it to the list */
9494
head = git__malloc(sizeof(git_remote_head));
95-
peel_len = strlen(name) + STRLEN(peeled);
95+
peel_len = strlen(name) + strlen(peeled);
9696
head->name = git__malloc(peel_len + 1);
9797
ret = p_snprintf(head->name, peel_len + 1, "%s%s", name, peeled);
9898
if (ret >= peel_len + 1) {

src/util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ extern char *git__strtok(char **end, const char *sep);
9393
extern void git__strntolower(char *str, int len);
9494
extern void git__strtolower(char *str);
9595

96-
#define STRLEN(str) (sizeof(str) - 1)
97-
9896
extern int git__fnmatch(const char *pattern, const char *name, int flags);
9997

10098
/*

tests/t15-config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ BEGIN_TEST(config16, "add a variable in a new section")
300300

301301
/* As the section wasn't removed, owerwrite the file */
302302
must_pass(git_filebuf_open(&buf, CONFIG_BASE "/config10", 0));
303-
must_pass(git_filebuf_write(&buf, "[empty]\n", STRLEN("[empty]\n")));
303+
must_pass(git_filebuf_write(&buf, "[empty]\n", strlen("[empty]\n")));
304304
must_pass(git_filebuf_commit(&buf));
305305
END_TEST
306306

0 commit comments

Comments
 (0)