From 39445b52330a2521a6f2cd596ea2cd32cdee5f85 Mon Sep 17 00:00:00 2001 From: peng Date: Thu, 2 Nov 2017 11:40:55 +0800 Subject: [PATCH] no memcpy for small size copy_cut_border/copy_make_boder --- src/mat.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/src/mat.cpp b/src/mat.cpp index 35ed2dc11..0d82891e9 100644 --- a/src/mat.cpp +++ b/src/mat.cpp @@ -348,8 +348,18 @@ static void copy_make_border_image(const Mat& src, Mat& dst, int top, int left, { outptr[x] = v; } - memcpy(outptr + left, ptr, src.w * sizeof(float)); - x += src.w; + if (src.w < 12) + { + for (; x < (left + src.w); x++) + { + outptr[x] = ptr[x - left]; + } + } + else + { + memcpy(outptr + left, ptr, src.w * sizeof(float)); + x += src.w; + } for (; x < w; x++) { outptr[x] = v; @@ -379,8 +389,18 @@ static void copy_make_border_image(const Mat& src, Mat& dst, int top, int left, { outptr[x] = ptr[0]; } - memcpy(outptr + left, ptr, src.w * sizeof(float)); - x += src.w; + if(src.w < 12) + { + for (; x < (left + src.w); x++) + { + outptr[x] = ptr[x - left]; + } + } + else + { + memcpy(outptr + left, ptr, src.w * sizeof(float)); + x += src.w; + } for (; x < w; x++) { outptr[x] = ptr[src.w - 1]; @@ -395,8 +415,18 @@ static void copy_make_border_image(const Mat& src, Mat& dst, int top, int left, { outptr[x] = ptr[0]; } - memcpy(outptr + left, ptr, src.w * sizeof(float)); - x += src.w; + if(src.w < 12) + { + for (; x < (left + src.w); x++) + { + outptr[x] = ptr[x - left]; + } + } + else + { + memcpy(outptr + left, ptr, src.w * sizeof(float)); + x += src.w; + } for (; x < w; x++) { outptr[x] = ptr[src.w - 1]; @@ -413,8 +443,18 @@ static void copy_make_border_image(const Mat& src, Mat& dst, int top, int left, { outptr[x] = ptr[0]; } - memcpy(outptr + left, ptr, src.w * sizeof(float)); - x += src.w; + if(src.w < 12) + { + for (; x < (left + src.w); x++) + { + outptr[x] = ptr[x - left]; + } + } + else + { + memcpy(outptr + left, ptr, src.w * sizeof(float)); + x += src.w; + } for (; x < w; x++) { outptr[x] = ptr[src.w - 1]; @@ -473,7 +513,17 @@ static void copy_cut_border_image(const Mat& src, Mat& dst, int top, int left) for (int y = 0; y < h; y++) { - memcpy(outptr, ptr, w*sizeof(float)); + if(w < 12) + { + for (int x = 0; x < w; x++) + { + outptr[x] = ptr[x]; + } + } + else + { + memcpy(outptr, ptr, w*sizeof(float)); + } outptr += w; ptr += src.w; }