Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 20th, 2011, 09:19 AM
Registered User
 
Join Date: Apr 2011
Location: Turnhout, Belgium
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Including NameTable Optimization (page 513)

Hi...

I don't know much about ASP.NET (yet), but I do know about polymorphism...
The code in listing 10-7 (and subsequent listings where the same technique is used), are not using the atomized strings...

From listing 10-7:

Code:
NameTable nt = new NameTable();
object book = nt.Add( "book" );
...
if ( ... && book.Equals( reader.LocalName ) )
The Add() method returns a string. So, the book variable, even though it's of type object, references a string object.
Since string overrides the Equals() method, the comparison will actually be a string comparison, and not an object reference comparison, as was intended. Polymorphism will cause the string override of Equals() to be called.

What the code should be in order to optimize it with the use of atomized strings is:
Code:
if ( ... && ReferenceEquals( book, reader.LocalName ) )
ReferenceEquals() is implemented by System.Object and compares the object references. book is a reference to the atomized string, so it will actually be compared to the atomized Reader.LocalName object reference.

David
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python code optimization icopec Python 2 December 13th, 2011 04:13 AM
A little optimization puzzle williamlove Pro VB 6 2 October 18th, 2009 02:17 AM
Optimization akkad C# 5 November 1st, 2006 04:27 AM
Optimization of ASP page with VBScript anandham VBScript 0 April 18th, 2005 05:03 AM
Query optimization SubodhKumar SQL Language 1 October 22nd, 2003 06:35 AM



All times are GMT -4. The time now is 01:41 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.