Bläddra i källkod

Optimize lsDive logic

Scott Lahteine 10 år sedan
förälder
incheckning
944090c19c
1 ändrade filer med 2 tillägg och 9 borttagningar
  1. 2
    9
      Marlin/cardreader.cpp

+ 2
- 9
Marlin/cardreader.cpp Visa fil

@@ -62,20 +62,13 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
62 62
 
63 63
       // Allocate enough stack space for the full path to a folder, trailing slash, and nul
64 64
       boolean prepend_is_empty = (prepend[0] == '\0');
65
-      int len = strlen(prepend) + (prepend_is_empty ? 1 : 0) + strlen(lfilename) + 1 + 1;
65
+      int len = (prepend_is_empty ? 1 : strlen(prepend)) + strlen(lfilename) + 1 + 1;
66 66
       char path[len];
67 67
 
68 68
       // Append the FOLDERNAME12/ to the passed string.
69 69
       // It contains the full path to the "parent" argument.
70 70
       // We now have the full path to the item in this folder.
71
-      if (prepend_is_empty) {
72
-        path[0] = '/'; // a root slash if prepend is empty
73
-        path[1] = '\0';
74
-      }
75
-      else
76
-        path[0] = '\0';
77
-
78
-      strcat(path, prepend);   // 1 character minimum
71
+      strcpy(path, prepend_is_empty ? "/" : prepend); // root slash if prepend is empty
79 72
       strcat(path, lfilename); // FILENAME_LENGTH-1 characters maximum
80 73
       strcat(path, "/");       // 1 character
81 74
 

Laddar…
Avbryt
Spara