<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Diese Funktion auf speed optimierbar?]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe einen einfache funktion und wollte wissen ob man diese irgendwie noch optimieren kann? z. B. durch bitshifts oder andere operationen.</p>
<p>Hier ist sie:</p>
<pre><code class="language-cpp">inline void getTilePositionInSurface (wchar_t value, int* x, int* y)
{
    if (!x || !y) return;

    if (value == L'0') { (*x) = 0; (*y) = 0; }
    if (value == L'1') { (*x) = 1; (*y) = 0; }
    if (value == L'2') { (*x) = 2; (*y) = 0; }
    if (value == L'3') { (*x) = 3; (*y) = 0; }
    if (value == L'4') { (*x) = 0; (*y) = 1; }
    if (value == L'5') { (*x) = 1; (*y) = 1; }
    if (value == L'6') { (*x) = 2; (*y) = 1; }
    if (value == L'7') { (*x) = 3; (*y) = 1; }
    if (value == L'8') { (*x) = 0; (*y) = 2; }
    if (value == L'9') { (*x) = 1; (*y) = 2; }
    if (value == L'A') { (*x) = 2; (*y) = 2; }
    if (value == L'B') { (*x) = 3; (*y) = 2; }
    if (value == L'C') { (*x) = 0; (*y) = 3; }
    if (value == L'D') { (*x) = 1; (*y) = 3; }
    if (value == L'E') { (*x) = 2; (*y) = 3; }
    if (value == L'F') { (*x) = 3; (*y) = 3; }
}
</code></pre>
<p>Danke im voraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/149889/diese-funktion-auf-speed-optimierbar</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 09:41:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/149889.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 11 Jun 2006 08:12:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:12:05 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe einen einfache funktion und wollte wissen ob man diese irgendwie noch optimieren kann? z. B. durch bitshifts oder andere operationen.</p>
<p>Hier ist sie:</p>
<pre><code class="language-cpp">inline void getTilePositionInSurface (wchar_t value, int* x, int* y)
{
    if (!x || !y) return;

    if (value == L'0') { (*x) = 0; (*y) = 0; }
    if (value == L'1') { (*x) = 1; (*y) = 0; }
    if (value == L'2') { (*x) = 2; (*y) = 0; }
    if (value == L'3') { (*x) = 3; (*y) = 0; }
    if (value == L'4') { (*x) = 0; (*y) = 1; }
    if (value == L'5') { (*x) = 1; (*y) = 1; }
    if (value == L'6') { (*x) = 2; (*y) = 1; }
    if (value == L'7') { (*x) = 3; (*y) = 1; }
    if (value == L'8') { (*x) = 0; (*y) = 2; }
    if (value == L'9') { (*x) = 1; (*y) = 2; }
    if (value == L'A') { (*x) = 2; (*y) = 2; }
    if (value == L'B') { (*x) = 3; (*y) = 2; }
    if (value == L'C') { (*x) = 0; (*y) = 3; }
    if (value == L'D') { (*x) = 1; (*y) = 3; }
    if (value == L'E') { (*x) = 2; (*y) = 3; }
    if (value == L'F') { (*x) = 3; (*y) = 3; }
}
</code></pre>
<p>Danke im voraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075394</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:12:05 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:20:06 GMT]]></title><description><![CDATA[<p>Mein Optimierungsvorschlag:<br />
Mach bei den if ein else.</p>
<pre><code class="language-cpp">inline void getTilePositionInSurface (wchar_t value, int* x, int* y)
{
    if (!x || !y) return;

    if (value == L'0') { (*x) = 0; (*y) = 0; }
    else if (value == L'1') { (*x) = 1; (*y) = 0; }
    else if (value == L'2') { (*x) = 2; (*y) = 0; }
    else if (value == L'3') { (*x) = 3; (*y) = 0; }
    else if ....
}
</code></pre>
<p>Wozu int* ? Muss das sein? ansonstens kannste auch int&amp; x, int&amp; y verwenden. Dann kannste auch x=0 und y=0 schreiben.<br />
Dann entfällt auch if (!x || !y) return;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075399</guid><dc:creator><![CDATA[DEvent]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:20:06 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:27:55 GMT]]></title><description><![CDATA[<p>hmn ob das else was bringt?</p>
<p>wegen den pointern: wenn ich eine Funktion aufrufe möchte ich schon wissen, ob daten geändert werden von dem was ich übergebe. das mache ich überall bei solchen funktionen und hat mir schon oft beim fehlerfinden geholfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075407</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:27:55 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:28:38 GMT]]></title><description><![CDATA[<p>Na mit switch/case.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075408</guid><dc:creator><![CDATA[-.-]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:28:38 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:33:40 GMT]]></title><description><![CDATA[<p>optimierer schrieb:</p>
<blockquote>
<p>hmn ob das else was bringt?</p>
</blockquote>
<p>Selbstverständlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075411</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075411</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:33:40 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:33:58 GMT]]></title><description><![CDATA[<p>muss switch/case nicht auch einen vergleich durchführen um zu &quot;wissen&quot; wo er reinfloppen soll?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075412</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:33:58 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:35:22 GMT]]></title><description><![CDATA[<p>optimierer schrieb:</p>
<blockquote>
<p>hmn ob das else was bringt?</p>
<p>wegen den pointern: wenn ich eine Funktion aufrufe möchte ich schon wissen, ob daten geändert werden von dem was ich übergebe. das mache ich überall bei solchen funktionen und hat mir schon oft beim fehlerfinden geholfen.</p>
</blockquote>
<p>Wie merkst du denn hier ob x oder y verändert wurde?</p>
<p>Mach doch dann</p>
<pre><code class="language-cpp">inline bool getTilePositionInSurface (wchar_t value, int&amp; x, int&amp; y)
{
    if (value == L'0') { x = 0; y = 0; return true; }
    if (value == L'1') { x = 1; y) = 0; return true; }
    if (value == L'2') { x = 2; y) = 0; return true; }
    if (value == L'3') { x = 3; y) = 0; return true; }
    if ....

    return false;
}
</code></pre>
<p>Jo mach switch-case. Mit wchar_t müsste das doch gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075414</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075414</guid><dc:creator><![CDATA[DEvent]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:35:22 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:36:30 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">inline bool getTilePositionInSurface (wchar_t value, int&amp; x, int&amp; y) 
{ 
    switch ( value )
    {
        case L'0': x = 0; y = 0; return true;
        ...
        default: return false;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1075415</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075415</guid><dc:creator><![CDATA[DEvent]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:37:26 GMT]]></title><description><![CDATA[<p>ganz einfach, ich sehe das am aufruf der funktion, ob darin dinge geändert werde dank &amp;. Würde ich es so machen wie du, sähe ich nicht direkt beim aufruf ob es für berechnungen benutzt wird oder daten geändert werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075417</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075417</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:37:26 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:39:40 GMT]]></title><description><![CDATA[<p>int&amp; ist in diesem Fall genauso wie int*.<br />
Nur du brauchst in der Funktion nicht mehr (*x) = 0 zu schreiben sondern kannst direkt x = 0. Es gibt in diesem Fall keinen Unterschied.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075418</guid><dc:creator><![CDATA[DEvent]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:39:40 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:42:15 GMT]]></title><description><![CDATA[<p>DEvent schrieb:</p>
<blockquote>
<p>int&amp; ist in diesem Fall genauso wie int*.<br />
Nur du brauchst in der Funktion nicht mehr (*x) = 0 zu schreiben sondern kannst direkt x = 0. Es gibt in diesem Fall keinen Unterschied.</p>
</blockquote>
<p>hab ich jemals gesagt ob es da einen unterschied gibt? man nu stell dich doch mal nicht so dämlich an!</p>
<p>Es geht um den Aufruf!</p>
<p>Beispiel:</p>
<pre><code class="language-cpp">int x = 4, y = 5;

 getTilePositionInSurface (L'A', x, y);
 getTilePositionInSurface (L'A', &amp;x, &amp;y);
</code></pre>
<p>Beim 2. (meine variante) sehe ICH direkt ob x und y verändert werden, bei variante 1 sehe ich nicht ob sie nur benutzt wird oder ob sie auch verändert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075421</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075421</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:42:15 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:49:55 GMT]]></title><description><![CDATA[<p>Boh! Auch noch rotz frech werden, wenn dir DEvent helfen will. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075425</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:49:55 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 08:53:08 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<p>Boh! Auch noch rotz frech werden, wenn dir DEvent helfen will. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
</blockquote>
<p>wenn er es seit sage und schreibe 3 posts nicht kapiert zeugt das nicht von seiner klugheit. frech war das nicht - nur ehrlich und direkt. dazu war nie die rede von einem rückgabewert, geschweige ob * und &amp; das selbe machen. es ging nur um optimierung und um den aufruf, das man daraus sehen kann, das daten verändert werden. Bei seiner variante konnte man das nicht auf anhieb beim aufruf sehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075427</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 08:53:08 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:17:18 GMT]]></title><description><![CDATA[<p>wchar_t sind doch auch angeordnet?</p>
<pre><code class="language-cpp">inline void getTilePositionInSurface (wchar_t value, int* x, int* y) 
{ 
  if (!x || !y) return; 

  static int number[][2] = {{0,0}, {1,0}, ... , {1,2}};
  static int alpha [][2] = {{2,2}, {3,2}, ... , {3,3}};

  if (value &gt;= L'0' and value &lt;= L'9') {
    (*x) = number[value - L'0'][0];
    (*y) = number[value - L'0'][0];
  } else if (value &gt;= L'A' and value &lt;= L'F') {
    (*x) = alpha[value - L'A'][0];
    (*y) = alpha[value - L'A'][0];
  }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1075438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075438</guid><dc:creator><![CDATA[Ponto]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:17:18 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:16:23 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6710">@Ponto</a><br />
Du bist echt mega genial! erste sahne! boah ey wie das abgeht! vielen vielen dank!!!!!!!!!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075444</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:16:23 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:19:09 GMT]]></title><description><![CDATA[<p>Ich würde auch eher die Funktion in zwei aufspalten. Eine die aus dem wchar_t die entsprechende Zahl macht und dann eine, welche die beiden Zuweisungen macht. Dann hat letztere nur ein Array und es sieht hübscher aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075445</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075445</guid><dc:creator><![CDATA[Ponto]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:19:09 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:20:25 GMT]]></title><description><![CDATA[<p>gute idee! nochmals vielen dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075448</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075448</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:20:25 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:27:55 GMT]]></title><description><![CDATA[<p>Dann brauchst du auch keine statischen Arrays mehr:</p>
<pre><code class="language-cpp">int wchar_to_int(wchart_t value) {
    if (value &gt;= L'0' and value &lt;= L'9') {
       return value - L'0';
    } else if (value &gt;= L'A' and value &lt;= L'F') {
       return value - L'A';
    }
    //throw exception
}

inline void getTilePositionInSurface (int value, int* x, int* y) 
{ 
  if (!x || !y) return; 

  (*x) = value % 4;
  (*y) = value / 4;
}
</code></pre>
<p>Die beiden Divisionen sollten sehr schnell gehen, da durch eine Zweierpotenz dividiert wird. Das macht der Kompiler schon ganz gut.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075454</guid><dc:creator><![CDATA[Ponto]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:27:55 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:35:17 GMT]]></title><description><![CDATA[<p>die division kann man doch mit einem bitshift beheben, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075460</guid><dc:creator><![CDATA[optimierer]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:35:17 GMT</pubDate></item><item><title><![CDATA[Reply to Diese Funktion auf speed optimierbar? on Sun, 11 Jun 2006 09:39:25 GMT]]></title><description><![CDATA[<p>optimierer schrieb:</p>
<blockquote>
<p>die division kann man doch mit einem bitshift beheben, oder?</p>
</blockquote>
<p>Ja. Aber das ist hier nicht notwendig. Es macht den Code weniger wartbar, da es schlechter lesbar ist.</p>
<p>Der Kompiler macht schon daraus einen Bitshift, wenn es sich auf deiner Plattform lohnt. So was selbst zu machen bringt gar nichts.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075465</guid><dc:creator><![CDATA[Ponto]]></dc:creator><pubDate>Sun, 11 Jun 2006 09:39:25 GMT</pubDate></item></channel></rss>